Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function returning '/' instead of an int in a string

Status
Not open for further replies.

dazappa007

Programmer
Oct 24, 2007
4
US
Code:
function protectInt(intnumb,tuInt,theRandd:integer):pchar; stdcall;
var mypchar:pchar;
begin
     protInts[intnumb]:=tuInt*theRandd;
     intMult[intnumb]:=theRandd; //can just ignore this line
     strpcopy(mypchar,inttostr(protInts[intnumb]));
     Result:=mypchar;
end;
OK basically what it's supposed to do is take in 3 integers. The first one is the array index (array is defined as 0..9 of integer). The second's value is set to 100 (always when I call this). The third is a random integer between 1 and 1000, and multiplying any whole random number from 100-1000 will always be a whole number so no problems there. Now: I'm not sure what protInts[0] ends up getting set to (seeing as this is a part of my dll). What I'm trying to do is convert protInts[0] to a pchar. It's a long way to do it and it returns '/' instead of '167000' or something similar =x
 
For the way your code is done, you need to allocate memory for "mypchar".

Code:
intlength := 2;
GetMem(myPChar, intlength);
intnumb := 1;
protInts[intnumb]:= 20;
strpcopy(mypchar,inttostr(protInts[intnumb]));
messagedlg(PChar(myPchar), mtInformation, [mbOK], 0);

You would do well to find a way to free this memory as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top