Autor Beitrag
Timbo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 166



BeitragVerfasst: Di 04.04.06 16:04 
Hallo,

wußte nicht, wo nach ich suchen soll, kann sein das es das schonmal gab...

ich habe 2 stringrids in unterschiedlichen formularen, mit unterschiedlichem inhalt und spaltenanzahl.
nun habe ich in grid1 eine ganze menge events programmiert, z.B. in OnDrawCell.

nun brauche ich genau die gleichen funktionen für grid2.

gibt es eine möglichkeit die events direkt in externen units abzufangen? oder muss ich in jedem grid welches dazu kommt die funktionen weiterleiten:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TFArtPflege.StringGridDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
  MyStringGridDrawCell(Sender,ACol,ARow,Rect,State); 
end;


vielen dank.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 04.04.06 17:52 
Hallo,

man könnte das folgendermaßen lösen, angenommen Du hast in Deiner Anwendung 2 Formulare/Units und auf jedem Formular ein StringGrid.
Nun erstellst Du in Unit1 die DrawCell-Prozedur und bindest die Unit2 in Unit1 ein.
Die Unit2 enthält im nachfolgenden Beispiel keine Prozeduren.
Die DrawCell-Prozedur zum StringGrid im Main-Formular kannst Du ja im OI zuweisen, die DrawCell für das Grid in Form2 wird dann zur Laufzeit vor der erstmaligen Anzeige zugewiesen.

Poste mal eine Beispiel-Unit, ist ja nicht so groß:
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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, StdCtrls;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure GridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
      State: TGridDrawState);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.GridDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  with TStringGrid(Sender) do
  begin
  if ARow = 1 then
    begin
    Canvas.Brush.Color := clRed;
    Canvas.FillRect(Rect);
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Assigned(Form2.StringGrid1.OnDrawCell) then
    Form2.StringGrid1.OnDrawCell := GridDrawCell;
  Form2.show;
end;

end.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )