[fpc-pascal]plugin frameworks.

Marco van de Voort marcov at stack.nl
Fri Jul 19 22:41:29 CEST 2002


> Ok all this considdered then I though I should share my typecase code with you and ask for help correcting it.
> 
> {$H+}
> program mysql_example;
> 
> ....
>   
> Function S2P (Str: AnsiString) : Pchar;
> 
> Begin
> 	
> 	S2P := StrAlloc (length(Str)+1);
> 	S2P := StrPCopy (S2P,Str);

StrPCopy is defined for shortstring only.
So it will typecast the ansistring shortstring first, and then pass it
to strpcopy to copy it into the pchar.
  	
> {Then when I want to do a mysql_query with web data I  would do something like:
> mysql_query(sock,s2p('SELECT * FROM table WHERE name="'+Data[1].value'));

Much to complicated. Remember that ansistrings are relatives of pchars,
and can be typecast to such beasts.

If the system will only read from the pchar, you can directly pass an
ansistring;

var s:ansistring;

S:='SELECT * FROM table WHERE NAME="'+Data[1].value+'"';
mysql_query(sock,pchar(S));
 




More information about the fpc-pascal mailing list