Die möglichkeiten sind viele. Wenn zum beispiel immer nur ein anderes Objekt auf dein Puffer-Objekt zugreifen soll, so kannst du das ganze über ein Event in deinem Puffer-Objekt lösen. Geht schnell kann jedoch nur ein anderes Objekt bedienen.
Eine weiter lösung ist die die UC gerade schon geschrieben hat. Ich hab das bei mir nicht mit einem Interface sondern mit einer Client Basis Klasse gemacht, von der dann alle anderen abgeleitet werden müssen. Mit einem Interface ist das natürlich noch schöner gelöst.
Ohne Interface sieht das bei mir im groben so aus:
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:
|
type
TPufferClient = class;
TPuffer = class(TObject) private FPufferClients : array of TPufferClient; protected procedure AfterRefresh; Virtual; public procedure AddPufferClient(aValue : TPufferClient); procedure DeletePufferClient(aValue : TPufferClient); published end;
TPufferClient = class(TObject) private FPuffer : TPuffer; protected procedure SetPuffer(aValue : TPuffer); public procedure Refresh; Virtual; abstract; destructor destroy; override; published property Puffer : TPuffer read FPuffer write SetPuffer; end; implementation
procedure TPuffer.AddPufferClient(aValue: TPufferClient); var index : integer; begin for index := 0 to high(FPufferClients) do begin if not assigned(FPufferClients[index]) then begin FPufferClients[index] := aValue; exit; end; end;
SetLength(FPufferClients,high(FPufferClients)+2); FPufferClients[high(FPufferClients)] := aValue; end;
procedure TPuffer.AfterRefresh; var index : integer; begin for index := 0 to high(FPufferClients) do try if assigned(FPufferClients[index]) then FPufferClients[index].Refresh; except end; end;
procedure TPuffer.DeletePufferClient(aValue: TPufferClient); var index : integer; begin for index := 0 to high(FPufferClients) do begin if FPufferClients[index] = aValue then begin FPufferClients[index] := nil; end; end; end;
procedure TPufferClient.SetPuffer(aValue : TPuffer); begin if aValue = FPuffer then exit;
if assigned(FPuffer) then FPuffer.DeletePufferClient(self);
if assigned(aValue) then aValue.AddPufferClient(self);
FPuffer := aValue; end;
destructor TPufferClient.destroy; begin SetPuffer(nil); inherited; end; |