Ignore:
Timestamp:
Nov 14, 2012, 2:58:35 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Ikony k záložkám jednotlivých tabulek.
  • Upraveno: Zobecněn systém pohledů na dynamickou strukturu.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormEdit.pas

    r7 r8  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   Buttons, ExtCtrls;
     9  Buttons, ExtCtrls, SpecializedList, SpecializedDictionary;
    1010
    1111type
     12  TControlType = (ctLabel, ctCheckBox, ctEdit, ctMemo, ctDate, ctTime,
     13    ctComboBox);
     14
     15  TFormItem = class
     16    Caption: string;
     17    Name: string;
     18    Visible: Boolean;
     19    Rect: TRect;
     20    ControlType: TControlType;
     21    TitlePlacement: TAlign;
     22  end;
     23
     24  { TFormItems }
     25
     26  TFormItems = class(TListObject)
     27    function AddItem(Caption, Name: string; ControlType: TControlType;
     28      Visible: Boolean; Rect: TRect): TFormItem;
     29  end;
    1230
    1331  { TFormEdit }
     
    1836    ButtonCancel: TButton;
    1937    procedure FormCreate(Sender: TObject);
     38    procedure FormDestroy(Sender: TObject);
    2039  private
    2140    { private declarations }
    2241  public
    23     { public declarations }
     42    RuntimeControls: TListObject;
     43    FormItems: TFormItems;
     44    Values: TDictionaryStringString;
     45    procedure Update;
    2446  end;
    2547
     
    2951implementation
    3052
     53{ TFormItems }
     54
     55function TFormItems.AddItem(Caption, Name: string; ControlType: TControlType;
     56  Visible: Boolean; Rect: TRect): TFormItem;
     57begin
     58  Result := TFormItem.Create;
     59  Result.Caption := Caption;
     60  Result.Name := Name;
     61  Result.Visible := Visible;
     62  Result.Rect := Rect;
     63  Result.ControlType := ControlType;
     64  Add(Result);
     65end;
     66
    3167{$R *.lfm}
    3268
     
    3571procedure TFormEdit.FormCreate(Sender: TObject);
    3672begin
     73  FormItems := TFormItems.Create;
     74  Values := TDictionaryStringString.Create;
     75  RuntimeControls := TListObject.Create;
     76end;
    3777
     78procedure TFormEdit.FormDestroy(Sender: TObject);
     79begin
     80  Values.Free;
     81  RuntimeControls.Free;
     82  FormItems.Free;
     83end;
     84
     85procedure TFormEdit.Update;
     86var
     87  NewControl: TControl;
     88  I: Integer;
     89  TitleRect: TRect;
     90const
     91  W = 50;
     92  H = 32;
     93begin
     94  RuntimeControls.Clear;
     95  for I := 0 to FormItems.Count - 1 do
     96  with TFormItem(FormItems[I]) do begin
     97    if TitlePlacement <> alNone then begin
     98      NewControl := TLabel.Create(Self);
     99      NewControl.Parent := Self;
     100      NewControl.Caption := Caption;
     101      TitleRect := Rect;
     102      case TitlePlacement of
     103        alLeft: TitleRect.Left := TitleRect.Left - 1;
     104        alRight: TitleRect.Left := TitleRect.Left + 1;
     105        alTop: TitleRect.Top := TitleRect.Top - 1;
     106        alBottom: TitleRect.Top := TitleRect.Top + 1;
     107      end;
     108      NewControl.SetBounds(TitleRect.Left * W, TitleRect.Top * H,
     109        (TitleRect.Right - TitleRect.Left) * W, (TitleRect.Bottom - TitleRect.Top) * H);
     110      NewControl.Show;
     111    end;
     112    if ControlType = ctLabel then begin
     113      NewControl := TLabel.Create(Self);
     114      NewControl.Parent := Self;
     115      NewControl.Caption := Values.Values[Name];
     116      NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
     117        (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
     118      NewControl.Show;
     119    end else
     120    if ControlType = ctEdit then begin
     121      NewControl.Show;
     122      NewControl := TEdit.Create(Self);
     123      TEdit(NewControl).Text := Values.Values[Name];
     124      NewControl.Parent := Self;
     125      NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H,
     126       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
     127      NewControl.Show;
     128    end else
     129    if ControlType = ctEdit then begin
     130      NewControl := TMemo.Create(Self);
     131      NewControl.Parent := Self;
     132      TMemo(NewControl).Lines.Text := Values.Values[Name];
     133      NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H,
     134       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
     135      NewControl.Show;
     136    end else
     137    if ControlType = ctCheckBox then begin
     138      NewControl := TCheckBox.Create(Self);
     139      NewControl.Parent := Self;
     140      TCheckBox(NewControl).Enabled :=  Values.Values[Name] = '1';
     141      NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H,
     142       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
     143      NewControl.Show;
     144    end else
     145    if ControlType = ctComboBox then begin
     146      NewControl := TComboBox.Create(Self);
     147      NewControl.Parent := Self;
     148      TComboBox(NewControl).Text := Values.Values[Name];
     149      NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H,
     150       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
     151      NewControl.Show;
     152    end;
     153  end;
    38154end;
    39155
Note: See TracChangeset for help on using the changeset viewer.