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

steinonline used Ask the Experts™
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
         i:=listbox1.perform(LB_SELECTSTRING,-1, integer(str);

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.
Watch Question

Do more with

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

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
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

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

Open in new window


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.


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