Delphi Listbox.Perform gives invalid typecast error when target platform is 64Bit Windows in Delphi XE2

steinonline
steinonline used Ask the Experts™
on
Hello Experts, My problem is that I do  a lookup of items in a listbox using code like this.  This has worked for me for many years.  However when I set the target platform to be 64Bit Windows, I am not able to successfully use this technique.  I'm assuming that this is because an integer is something different in the 64 Bit World.  Here's the code.

The Error I'm getting is "Invalid Typecast"

var i:integer;
var str:string;

// assume there is an edit box named edit1, and a listbox named ListBox1
begin
   
         str:=edit1.text;
         i:=listbox1.perform(LB_SELECTSTRING,-1, integer(str);
end;

This will work just fine when target platform is set to 32bit Windows.

I have not been able to find any material on this matter anywhere.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ferruccio AccalaiSenior developer, analyst and customer assistance

Commented:
I'd use i:=listbox1.perform(LB_SELECTSTRING,-1, LPARAM(Pchar(str)));

Anyway why don't you use simply Listbox1.items.indexof(str)?
Oracle dba
Top Expert 2009
Commented:
besides you having a ) missing in your code
where did you get your sample code ??

all these have a longint typecast of pointer to an array of char
http://delphi.about.com/od/vclusing/a/lb_incremental.htm
http://www.delphicorner.f9.co.uk/articles/misc6.htm
http://www.delphipages.com/forum/showthread.php?t=197036

var i:integer;
   str : array[0..255] of Char;
 begin
   StrPCopy(str, Edit1.Text) ;
   ListBox1.Perform(LB_SELECTSTRING, -1, LongInt(@str)) ;
 end;

Open in new window

Author

Commented:
I simply forgot to type the ) when I wrote the code down.  I did find however that the first parameter would not compile as 64bit with -1 as value.  Must be 0.  Then it all works fine.

Cheers

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial