Link to home
Start Free TrialLog in
Avatar of steinonline
steinonline

asked on

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

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.
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

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

Anyway why don't you use simply Listbox1.items.indexof(str)?
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of steinonline
steinonline

ASKER

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