Einzelnen Beitrag anzeigen

Andreas L.
(Gast)

n/a Beiträge
 
#3

Re: Array of TImage von anderer unit benutzen

  Alt 8. Mai 2007, 20:22
Hi,
danke für deine Antwort. Die Anwendung läuft jetzt. Die Bilder tauchen jedoch nicht auf wenn ich meine Add-Routine aufrufe. ich weiß jedoch nicht warum?!?!

Die Unit:
Delphi-Quellcode:
unit ElementList;

interface

 uses
  ExtCtrls, pngimage, graphics, SysUtils, Classes, forms, controls,
  contnrs;

 type
  TElementType = (etText, etImage, etChart, etTable, etCode, etHTML, etMedia);

 type
  TElementList = class(TScrollBox)
   constructor Create(AOwner: TComponent); override;
   function Add(ElemType: TElementType; Content: String):Integer;
   procedure Refresh;
   procedure Move(OldPosition, NewPosition: Integer);
  end;

var
 Icons: Array of TImage;

implementation

var
 Items: TObjectList;

constructor TElementList.Create(AOwner: TComponent);
begin

 inherited Create(AOwner);
 BevelInner := bvNone;
 BevelKind := bkFlat;
 BevelOuter := bvLowered;
 BorderStyle := bsNone;

 Items := TObjectList.Create;

 SetLength(Icons, 7);
 Icons[0] := TImage.Create(Self);
 Icons[1] := TImage.Create(Self);
 Icons[2] := TImage.Create(Self);
 Icons[3] := TImage.Create(Self);
 Icons[4] := TImage.Create(Self);
 Icons[5] := TImage.Create(Self);
 Icons[6] := TImage.Create(Self);

end;

procedure TElementList.Move(OldPosition, NewPosition: Integer);
begin

 Items.Move(OldPosition, NewPosition);
 Refresh;

end;

procedure TElementList.Refresh;
var
 i, position: Integer;
begin

 position := 0;

 for i := 0 to Items.count - 1 do
  begin

   (Items.Items[i] as TPanel).Visible := false;

  end;

 for i := 0 to Items.count - 1 do
  begin

   (Items.Items[i] as TPanel).Top := position + 80;
   (Items.Items[i] as TPanel).Visible := true;

  end;

end;

function TElementList.Add(ElemType: TElementType; Content: String):Integer;
var
 layer: TPanel;
 imgtype: TImage;
begin

 layer := TPanel.Create(Self);
 with layer do
  begin

   BevelInner := bvNone;
   BevelKind := bkNone;
   BevelOuter := bvNone;
   BorderStyle := bsNone;
   Align := alTop;
   Height := 80;
   Parent := Self;
   Visible := false;
   Color := clBlack;
   Result := Items.Add(layer);

  end;

 imgtype := TImage.Create(layer);
 with imgtype do
  begin

   Parent := layer;
   Visible := true;
   Left := 8;
   Top := 8;
   Height := 28;
   Width := 28;

  end;

 if ElemType = etText then
  begin

   imgtype.Picture.graphic := Icons[0].Picture.graphic;

  end
 else if ElemType = etImage then
  begin

   imgtype.Picture.graphic := Icons[1].Picture.graphic;

  end
 else if ElemType = etChart then
  begin

   imgtype.Picture.graphic := Icons[2].Picture.graphic;

  end
 else if ElemType = etTable then
  begin

   imgtype.Picture.graphic := Icons[3].Picture.graphic;

  end
 else if ElemType = etCode then
  begin

   imgtype.Picture.graphic := Icons[4].Picture.graphic;

  end
 else if ElemType = etHTML then
  begin

   imgtype.Picture.graphic := Icons[5].Picture.graphic;

  end
 else if ElemType = etMedia then
  begin

   imgtype.Picture.graphic := Icons[6].Picture.graphic;

  end;

end;

end.
Die Zuweisung der Bilderimg ButtonClick einer anderen Unit:
Delphi-Quellcode:
 Icons[0].Picture.graphic := text.Picture.graphic;
 Icons[1].Picture.graphic := image.Picture.graphic;
 Icons[2].Picture.graphic := chart.Picture.graphic;
 Icons[3].Picture.graphic := table.Picture.graphic;
 Icons[4].Picture.graphic := syntax.Picture.graphic;
 Icons[5].Picture.graphic := html.Picture.graphic;
 Icons[6].Picture.graphic := media.Picture.graphic;
  Mit Zitat antworten Zitat