View Single Post
  #1  
Old 09-19-2005, 03:08 AM
fredstain fredstain is offline
Junior Member
 
Join Date: Sep 2005
Posts: 6
Default !NEED HELP! Please look here..

Can anyone help?... converting some java into delphi (pascal)



Hi I would like to have this code translated into Delphi 6 enterprise (Pascal).

>>This I picture, should be created in a separete .pas file called strangebase.pas:
So i know i need the StrangeBase.pas created and with two procedures or functions in it
(one called: makeBase and the other: parseBase) or perhaps it is not nessasery to create
the procedures/functions in a separate fil, anyways the result would be usefull.

I hope Sufficient information has been posted, for the right people to comment/reply on this post.
*/Please excuse all misspelling & bad grammer/*

(The source originates from a java *.class file)
________________________________________________
package JUtil.math;


public class StrangeBase
{

public StrangeBase()
{
}

public static String makeBase(int i, int j)
{
StringBuffer stringbuffer = new StringBuffer();
int k;
for(k = j; k < i; k *= j);
do
{
int l = i / k;
char c = (char)(startchar + l);
stringbuffer.append(c);
i -= k * l;
k /= j;
} while(k > 0);
return stringbuffer.toString();
}

public static int parseBase(String s, int i)
{
int j = 0;
for(int k = 0; k < s.length(); k++)
{
j *= i;
j += s.charAt(k) - startchar;
}

return j;
}

public static char startchar = 'b';

}
________________________________________________

>>Now in my delphi application in eg. a button's "onclick" procedure I need this traslated to Delphi 6 enterprise
(Pascal) also (As you see I started to tranlate but quickly lost track of the whole thing):

uses strangebase;

procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
s: string;
begin
s:=edit1.text //Input to convert in stangebase procedures
StrangeBase.startchar:='a';//Set correct startchar for the whole "algorithem"
i:= StrangeBase.parseBase(s, 13) & 0x3fff; //Decode input and place in integer i
edit1.text:= StrangeBase.makeBase(i * i, 17));//Use the decoded data to generate final result of code consisting on letters
end;

-Thx in adwance!

*/Please excuse all misspelling & bad grammer/*


RE: Can anyone help?... converting some java into delphi (pascal)



can you tell me what there purpose or what those two routines are suppose to do I can write the rotuines for you based on what it is suppose to do

function makeBase(i, j: Integer) : String;
begin
//result:=
end;

function parseBase(s: String; I: Integer) Integer;
begin
//result:=
end;

i gotta refresh my knowledge on Java loops

If this helps, please accept as answer!

Thanks!

UnSysApps



RE: Can anyone help?... converting some java into delphi (pascal)



I can't beieve this is stumping me - i really need to get back to java and freshen up...

type

TStrangeBase = class
public
StartChar: Char;
function makeBase(i, j: Integer) : String;
function parseBase(S: String; I: Integer): Integer;
constructor Create;
end;

constructor TStrangeBase.Create;
begin
inherited Create;
STartChar:= 'b';
end;

function TStrangeBase.makeBase(i, j: Integer) : String;
var
K, L: Integer;
C: Char;
begin
result:= '';
while K < I do
begin

end;
//result:=
end;

function TStrangeBase.parseBase(S: String; I: Integer): Integer;
const StartChar = 'b';
var
J, K: Integer;
begin
for K:= 1 to Length(S) do
begin
//
end;
//result:= ;
end;

If this helps, please accept as answer!

Thanks!

UnSysApps



RE: Can anyone help?... converting some java into delphi (pascal)



-Hi Unsysapps & others!
{I really appreciate the fast respond-time}

>> Okay so I will start by answering your first question:

Q: "can you tell me what there purpose or what those two routines are suppose to do I can write the routines for you based on what it is suppose to do"

A: I really like to get all programming of "parsebase" and "makebase" to reside in a separate .pas file. (Unit)

The two routines/functions should work this way:

-First in my own project i would like to call my
"stangebase.pas" and set the start char to a. (StrangeBase.startchar:='a')

-Then the string s is set to hold: abdmkh (This input is eventually randomly generated)

- The result of parseBase are placed in integer: i

i:= StrangeBase.parseBase(s, 13) & 0x3fff; (Now this will not compile due to the lack of translation from java to Delphi)

- So now the function parsebase has been called so lets forget it for a while.
- My code is now placed in integer: i (somehow converted to digits instead of abdmkh)
- Now the FINAL result are placed in edit1: edit1.text:= StrangeBase.makeBase(i * i, 17));
- Now in my edit1 the text result of start-input: abdmkh should the exactly as follow: aojmqhp (Without  of course)

>>When the result code in edit1 returns aojmqhp when using input abdmkh the whole thing is working.

So let me draw the attention back on your other post:
It seems to me like you had some problems as well translating it, properly because my lack of proper writing/explanations. So I hope this posting has brought some light on what it is supposed to return.

Regards: Fredstain

//*Please excuse all misspelling and bad grammar*//
Reply With Quote