Autor Beitrag
HECHT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24


D7
BeitragVerfasst: Fr 08.04.05 12:30 
Problemstellung:
Ich habe auf abgeleiteten Standardkomponenten z.B. Grid eigene Properties definiert wie z.B. ReportTitle. Ich habe kapiert wie man im Objektinspektor einen Lookup anzeigt etc.
Nun möchte ich aber meine eigenen Properties von den Standardproperties visuelle unterscheiden können. Ich möchte eine Gruppe wie z.B. Font, welche man aufklappen kann.
Wie kriege ich eine solche Gruppe(Node) hin? Ganz cool wäre natürlich noch die Gruppe farblich oder mit Ikonen oder so hervorzugeben.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
type
  TmyDBGridEh = class(TDBGrid)
  private
    FReportTitle: String;
  protected
    procedure SetReportTitle(Const Value: string);
    function GetReportTitle: string;
  public

  published
    property ReportTitle: String read GetReportTitle write SetReportTitle;


Funktioniert alles wunderprächtig und wird im Objektinspektor angezeigt, nur beim gruppieren happerts.
Bsp. im Objektinspektor:
+Font
-Color
-Size

und ich möchte:
+ReportSettings
-ReportTitle
-FileName

Moderiert von user profile iconMotzi: Code- durch Delphi-Tags ersetzt.
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Fr 08.04.05 18:30 
wie soll das mit einem String alleiine denn gehen ? Es geht um Subkomponenten. Diese müssen aber auch die untergeordneten Eigenschaften mitbringen. Bei einem String ist das aber nicht der Fall. Deshalb vorab Stichwort : SetSubComponent. 8)

_________________
Gruß
Hansa
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Sa 09.04.05 11:09 
Mit SetSubComponent hat das eher wenig zu tun, eher mit einem Nachfolger von TPersistent. Du musst eine Klasse von TPersistent ableiten. Dieser Klasse verpasst du dann die ganzen Properties, die du in der Gruppe haben willst (natürlich als published) und in deiner Komponente brauchst du dann eine Eigenschaft, die eine Instanz dieser Klasse darstellt (selbstverständlich auch wieder als published).

Gruß, Motzi

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
HECHT Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24


D7
BeitragVerfasst: Mo 11.04.05 14:46 
Danke Motzi und Hansa,
Mit Eurer Hilfe habe ich das Kind zum schaukeln gebracht. Ich habe die Variante von Motzi gewählt, habe mir TPersistent abgeleitet. Die Lösung ist eigentlich simpel, man benötigt 2 Klassen Hauptklasse und Subklasse(mit den Eigenschaften) und deklariert die Subklasse in der Hauptklasse, wobei die Hauptklasse die eigentliche Komponente bildet.

Gruss
HECHT

Zweck's vervollständigung habe ich den Code einmal auf die Problematik reduziert und angehängt:


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:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
unit aqDBGridEh;

interface

uses //für das Bsp. nicht so abtippen!
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    Db, Grids, DBTables, ExtCtrls, DBCtrls, StdCtrls, Menus,
    DBGridEh, PrnDbgeh, Dbgrids, OracleData, Registry, DBGridEhImpExp;

type

  TReportSettings = class(TPersistent)
  private
    FReportHeader: String;
    FReportFooter: String;
  protected
  public
    procedure SetReportHeader(Const Value: string);
    function GetReportHeader: string;
    procedure SetReportFooter(Const Value: string);
    function GetReportFooter: string;
    constructor create;
  published
    property ReportHeader: String read GetReportHeader write SetReportHeader;
    property ReportFooter: String read GetReportFooter write SetReportFooter;
  end;


  TaqDBGridEh = class(TDBGridEh)
  private
    FReportTitle: String;
    FReportSettings: TReportSettings;
  protected
    procedure SetReportTitle(Const Value: string);
    procedure SetReportSettings(Const Value: TReportSettings);
    function GetReportTitle: string;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property ReportTitle: String read GetReportTitle write SetReportTitle;
    property ReportSettings: TReportSettings read FReportSettings write SetReportSettings;
  end;

  procedure Register;


implementation

uses
  aqDBGridEhSaveAs, aqDBGridFilterNew, aqDBGridSortResult;

procedure Register;
begin
  RegisterComponents('Heiko Kueng', [TaqDBGridEh]);
end;


constructor TReportSettings.create;
begin
  inherited;
  FReportHeader:= 'Header';
  FReportFooter:= 'Footer';
end;


constructor TaqDBGridEh.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FReportSettings := TReportSettings.Create;
end;

destructor TaqDBGridEh.Destroy;
begin
  FReportSettings.Free;
  inherited Destroy;
end;


//Nachfolgend zur verfollständigung die ganze GET/SET Geschichte.

function TaqDBGridEh.GetReportTitle: string;
begin
  result := FReportTitle;
end;

procedure TaqDBGridEh.SetReportTitle(const Value: string);
begin
  FReportTitle := Value;
end;

function TReportSettings.GetReportHeader: string;
begin
  result := FReportHeader;
end;

procedure TReportSettings.SetReportHeader(const Value: string);
begin
  FReportHeader := Value;
end;

function TReportSettings.GetReportFooter: string;
begin
  result := FReportFooter;
end;

procedure TReportSettings.SetReportFooter(const Value: string);
begin
  FReportFooter := Value;
end;

procedure TaqDBGridEh.SetReportSettings(const Value: TReportSettings);
begin
  if Value <> ReportSettings then
  begin
    FReportSettings := Value;
  end;
end;


end.



Falls jemand noch ein Bildli davon braucht... ObjInsp_RepSett.JPG

Moderiert von user profile iconUGrohne: Code- durch Delphi-Tags ersetzt.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 11.04.05 15:08 
Hallo!

Zwei Details:
  1. Solltest du die Methode Assign in der Klasse TReportSettings implementieren (Überschreiben)
  2. In SetReportSettings solltest du dann Assign benutzen:
    ausblenden Delphi-Quelltext
    1:
    FReportSettings.Assign (Value);					
Gruß
Tino
HECHT Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24


D7
BeitragVerfasst: Mo 11.04.05 17:01 
Müsste man eigentlich machen...
Hier nochmals der revidierte Code mit AssignForTino() :D
..sollte dann etwa so aussehen:


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:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
unit aqDBGridEh;


interface


uses //für das Bsp. nicht so abtippen!
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    Db, Grids, DBTables, ExtCtrls, DBCtrls, StdCtrls, Menus,  
    DBGridEh, PrnDbgeh, Dbgrids, OracleData, Registry, DBGridEhImpExp;  

 
type  


  TReportSettings = class(TPersistent)
  private  
    FReportHeader: String;  
    FReportFooter: String;  
  protected
    procedure AssignTo(Dest: TPersistent); override;
  public
    procedure SetReportHeader(Const Value: string);
    function GetReportHeader: string;
    procedure SetReportFooter(Const Value: string);
    function GetReportFooter: string;
    constructor create;
    procedure Assign(Source : TPersistent); override;
  published
    property ReportHeader: String read GetReportHeader write SetReportHeader;
    property ReportFooter: String read GetReportFooter write SetReportFooter;
  end;


 
  TaqDBGridEh = class(TDBGridEh)  
  private  
    FReportTitle: String;  
    FReportSettings: TReportSettings;
  protected
    procedure SetReportTitle(Const Value: string);  
    procedure SetReportSettings(Const Value: TReportSettings);  
    function GetReportTitle: string;  
  public  
    constructor Create(AOwner: TComponent); override;  
    destructor Destroy; override;  
  published  
    property ReportTitle: String read GetReportTitle write SetReportTitle;  
    property ReportSettings: TReportSettings read FReportSettings write SetReportSettings;  
  end;  

 
  procedure Register;

 

 
implementation  

 
uses  
  aqDBGridEhSaveAs, aqDBGridFilterNew, aqDBGridSortResult;  

 
procedure Register;  
begin  
  RegisterComponents('REPORTER', [TaqDBGridEh]);  
end;  




constructor TReportSettings.create;
begin
  inherited;
  FReportHeader:= 'Header';
  FReportFooter:= 'Footer';
end;


procedure TReportSettings.Assign(Source: TPersistent);
begin
  if Source is TReportSettings then begin
    Self.ReportHeader := TReportSettings(Source).ReportHeader;
    Self.ReportFooter := TReportSettings(Source).ReportFooter;
  end else begin
    inherited Assign(Source);
  end;
end;


procedure TReportSettings.AssignTo(Dest: TPersistent);
begin
  if Dest is TReportSettings then begin
    TReportSettings(Dest).ReportHeader := Self.ReportHeader;
    TReportSettings(Dest).ReportFooter := Self.ReportFooter;
  end else begin
    inherited AssignTo(Dest);
  end;
end;


constructor TaqDBGridEh.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);  
  FReportSettings := TReportSettings.Create;  
end;  

 
destructor TaqDBGridEh.Destroy;  
begin  
  FReportSettings.Free;  
  inherited Destroy;  
end;  

 

 
//Nachfolgend zur verfollständigung die ganze GET/SET Geschichte.  

 
function TaqDBGridEh.GetReportTitle: string;  
begin  
  result := FReportTitle;  
end;  

 
procedure TaqDBGridEh.SetReportTitle(const Value: string);  
begin  
  FReportTitle := Value;  
end;  

 
function TReportSettings.GetReportHeader: string;  
begin
  result := FReportHeader;  
end;  

 
procedure TReportSettings.SetReportHeader(const Value: string);  
begin  
  FReportHeader := Value;  
end;  

 
function TReportSettings.GetReportFooter: string;  
begin  
  result := FReportFooter;  
end;  

 
procedure TReportSettings.SetReportFooter(const Value: string);  
begin  
  FReportFooter := Value;  
end;  

 
procedure TaqDBGridEh.SetReportSettings(const Value: TReportSettings);  
begin
  if Value <> ReportSettings then
  begin
    FReportSettings.Assign (Value);
  end;
end;


end.


Zuletzt bearbeitet von HECHT am Do 23.06.05 17:57, insgesamt 1-mal bearbeitet
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 11.04.05 17:25 
user profile iconHECHT hat folgendes geschrieben:
..sollte dann etwa so aussehen:

Sieht vorbildlich aus. ;-)