Autor Beitrag
schuetzejanett
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Di 23.01.07 21:54 
Hallo,

wollte eine Klasse um eine Liste von Regionen zu verwalten, damit ich später bei Klick auf eine Grafik überprüfen kann auf welchen Teil der grafik ich geklickt habe.
wie mache ich es jetzt das ich in einer liste nur diese regionen speichern kann?
ich habe mir jetzt einen Typ dartBoardField deklariert in dem eine region und der zugehörige name gespeichert ist
Will ich diesen jetzt allerdings der Liste hinzufügen erhalte ich die nachricht
Inkompatible Typen Dartfield und Pointer

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
unit DartBoard;

interface

uses
  Classes, SysUtils, Dialogs, Windows;

  type DartField = record
       Region  : HRGN;
       Field   : String
       end;

  type TDartBoard = class(TList)

  private

  public

  procedure Add(Field: Dartfield);
  end;

implementation

{ TDartBoard }

procedure TDartBoard.Add(Field: DartField);
begin
inherited Add(Field);
end;

end.


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 24.01.07 01:20 
Moin!

Es ist IMHO nicht so schlau, verschiedene Ansätze zu mischen. Warum nicht so? ;)
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
unit DartBoard;  
 
interface  
 
uses  
  Classes, SysUtils, Dialogs, Windows, Contnrs;
 
type
  TDartField = class(TObject)
  private
    FRegion: HRGN; // was auch immer das für ein Typ ist?
    FName: String;
  public
    property Region: HRGN read FRegion write FRegion;
    property Name: String read FName write FName;
  end;  

  TDartBoard = class(TObject)
  private  
    FRegions: TObjectList;
    function GetRegion(Index: Integer): TDartField;
  public
    constructor Create;
    destructor Destroy; override;
    property Regions: TObjectList read FRegions;
    property Region[Index: Integer]: TDartField read GetRegion;
    procedure AddRegion(ARegion: HRGN; AName: String);
  end;  

implementation  
 
{ TDartBoard }  

constructor TDartBoard.Create;
begin
  inherited// geerbten Konstruktor aufrufen
  FRegions := TObjectList.Create;
end;

destructor TDartBoard.Destroy;
begin
  FRegions.Free; // gibt auch die enthaltenen Objekte frei
  inherited// geerbten Destruktor aufrufen
end;

function TDartBoard.GetRegion(Index: Integer): TDartField;
begin
  Result := TDartField(FRegions.Items[Index]);
end;

procedure TDartBoard.AddRegion(ARegion: HRGN; AName: String);
  var
    DartField: TDartField;
begin  
  DartField := TDartField.Create;
  DartField.Region := ARegion;
  DartField.Name := AName;
  FRegions.Add(DartField);
end;  
 
end.

Runtergeschrieben, sollte aber funktionieren. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.