Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi ComboBox und cards.dll (https://www.delphipraxis.net/110379-combobox-und-cards-dll.html)

The Lord 17. Mär 2008 11:20


ComboBox und cards.dll
 
Hi DP'ler,

ich habe schon einige Erfahrungen mit Pascal und arbeite auch länger schon mit Delphi, aber ich habe mich dort noch nie mit Objekten befasst.
Ich habe bis jetzt nur mit c++ mit Objekten gearbeitet.

Ich benutze gerade die cards.dll um damit ein kleines Progrämmchen zu machen. Ich habe vor eine CombobBox mit den möglichen Karten zu füllen, um diese dann via OnChance zu zeigen.

Die ComboBox wird wie folgt gefüllt:
Delphi-Quellcode:
procedure fill_combobox;
var CardFace : TCardFaces;    
    x : string;
i : integer;  
begin
   i:=1;
   for CardFace := faceAce to faceKing do
    begin      
      Form1.Combobox2.Items.AddObject(IntToStr(i), TObject(CardFace));
      i:=i+1;
    end;
end;
Das funktioniert auch.

Aber ich weiß nicht, wie ich diese jetzt zeigen kann, wenn ich das Ereignis in der ComboBox auslöse. Wenn ich ganz normal eine Funktion aufrufe, dann kann ich diese auch zeigen.

Ich habe folgendes probiert:

Delphi-Quellcode:
procedure TForm1.ComboBox2Change(Sender: TObject);
var
  CardFace : TCardFaces;
  x, y : Integer;
begin
  x:=Image2.Left;
  y:=Image2.Top;
  CardFace:=ComboBox2.Items.Objects[ComboBox2.ItemIndex];
  Cards.DrawCard(Canvas.Handle, Point(x, y), suitSpades, CardFace, FALSE);
end;
Das gibt natürlich einen Error: Inkompatible Typen TObject und TCardFaces.

Wie kann ich das Problem lösen?

Hoffentlich könnt ihr mir helfen :)

Liebe Grüße

mkinzler 17. Mär 2008 11:23

Re: ComboBox und cards.dll
 
Delphi-Quellcode:
CardFace:= (ComboBox2.Items.Objects[ComboBox2.ItemIndex] as TCardFaces);

Muetze1 17. Mär 2008 15:05

Re: ComboBox und cards.dll
 
Da TCardFaces eindeutig kein Objekt oder Klasse ist, muss es im Gegensatz zu mkinzler's Lösung so lauten:

Delphi-Quellcode:
CardFace:= TCardFaces(ComboBox2.Items.Objects[ComboBox2.ItemIndex]);

The Lord 19. Mär 2008 08:10

Re: ComboBox und cards.dll
 
Zitat:

Zitat von Muetze1
Delphi-Quellcode:
CardFace:= TCardFaces(ComboBox2.Items.Objects[ComboBox2.ItemIndex]);

Funktioniert.
Danke :)
:dp:


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:09 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz