Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.delphi.misc > #19185

Re: array in array

From Jens Kallup <kallup.jens@web.de>
Newsgroups de.comp.lang.delphi.misc
Subject Re: array in array
Date 2022-02-19 13:30 +0100
Organization kallup.net - non-profit
Message-ID <j7c66rFgplpU1@mid.individual.net> (permalink)
References <j7buqmFfdk4U1@mid.individual.net> <suqi7c$1e5j0$1@solani.org> <j7c3k5Fg9c4U1@mid.individual.net> <suqmqa$1e8o1$1@solani.org>

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Am 19.02.2022 um 13:11 schrieb stefan:

> Du müsstest mal erklären, was du eigentlich erreichen willst.

Also:
ich habe ein Programm, das so wenig CODE + DATA + BSS einnimmt.
Weil das letzenends auch eine Frage der Wartbarkeit betrifft.

Der übliche "kindliche" Weg wäre Spagetty Code, bei dem jeder
(ich sag jetzt mal TButton) einzeln erzeugt, und bearbeitet werden
muss, wenn Änderungen am Programm vorgenommen werden.

Besser erscheint mir, der etwas kompliziertere Weg, die TComponent
Objekte während der Laufzeit zu erstellen, anstelle die Ressourcen
aka .dfm in die .exe mit aufzunehmen.

Das ginge auch, aber Windows ist dann etwas eigen was Ressourcen
anbelangt (sind zwar manchmal schneller als die direkte Speicher
Allokation - nehmen aber auch manchmal doppelt zuviel Arbeitsspeicher
weg).

Also habe ich versucht bestimmte Teile meines Programmes innerhalb
von Records auszulagern.

Daraus ist dann folgendes geworden:

type
   recordMyIconsStructure = record
     p: String;  // picture
     c: String;  // design class
     h: String;  // hint
   end;
var
   // --------------------
   // standard palette :
   // --------------------
   recordMyIcons_Std : Array[0..22] of recordMyIconsStructure = (
     (p: 'tmouse';         c: 'TMouse';        h: 'Mouse Cursor / 
Selector'),
     (p: 'tmainmenu';      c: 'TMainMenu';     h: 'Create / Edit the 
application main menu.'),
     (p: 'tpopupmenu';     c: 'TPopupMenu';    h: 'Create / Edit the 
application popup menu.'),
     (p: 'tlabel';         c: 'TLabel';        h: 'Label for Text.'),
     (p: 'tbutton';        c: 'TButton';       h: 'Button that can be 
click per mouse.'),
     (p: 'tedit';          c: 'TEdit';         h: 'Add Entryfield for 
text input.'),
     (p: 'tmemo';          c: 'TMemo';         h: 'Editor/Memo for Edit 
multiple line Texts.'),
     (p: 'tlistbox';       c: 'TListBox';      h: 'List of Strings in a 
box.'),
     (p: 'ttreeview';      c: 'TTreeView';     h: 'List of Node Texts as 
Tree view.'),
     (p: 'tcombobox';      c: 'TComboBox';     h: 'Combobox - a one line 
List of Text.'),
     (p: 'tstringgrid';    c: 'TStringGrid';   h: 'String Grid like 
Edits in tabular form.'),
     (p: 'tradiobutton';   c: 'TRadioButton';  h: 'A single Radio button.'),
     (p: 'tgroupbox';      c: 'TGroupBox';     h: 'Groupbox for Radio 
buttons.'),
     (p: 'timage';         c: 'TImage';        h: 'Display 
Images/Pictures.'),
     (p: 'tspinedit';      c: 'TSpinEdit';     h: 'Value Spinner with 
up/down Buttons.'),
     (p: 'tdatecombobox';  c: 'TDateComboBox'; h: 'Date changer ComboBox-'),
     (p: 'tprogressbar';   c: 'TProgressBar';  h: 'A Progess Bar 
Component.'),
     (p: 'tsplitter';      c: 'TSplitter';     h: 'Splitter for 
Components.'),
     (p: 'tpanel';         c: 'TPanel';        h: 'Panel container.'),
     (p: 'tpagecontrol';   c: 'TPageControl';  h: 'Multiple Page 
Container.'),
     (p: 'tstatusbar';     c: 'TStatusBar';    h: 'Place a Status-Bar at 
Bottom of Window.'),
     (p: 'tpaintBox';      c: 'TPaintBox';     h: 'Paint Box Drawer 
Component.'),
     (p: 'tshape';         c: 'TShape';        h: 'A Shape Drawer 
Component.')
   );

   // ----------------------------
   // database controls palette :
   // ----------------------------
   recordMyIcons_db : Array[0..6] of recordMyIconsStructure = (
     (p: 'tmouse';      c: 'TMouse';      h: 'Mouse Cursor / Selector'),
     (p: 'tdbedit';     c: 'TDBEdit';     h: 'db-Entryfield for 
Text-Input.'),
     (p: 'tdbmemo';     c: 'TDBMemo';     h: 'db-Editor/Memo for huge 
Text.'),
     (p: 'tdbimage';    c: 'TDBImage';    h: 'db-Image.'),
     (p: 'tdbgrid';     c: 'TDBGrid';     h: 'db-Table Grid.'),
     (p: 'tdblistbox';  c: 'TDBListBox';  h: 'db-ListBox.'),
     (p: 'tdbcombobox'; c: 'TDBComboBox'; h: 'db-ComboBox.')
   );

   // --------------------------
   // database access palette :
   // --------------------------
   recordMyIcons_dbSrc : Array[0..5] of recordMyIconsStructure = (
     (p: 'tmouse';     c: 'TMouse';      h: 'Mouse Cursor / Selector'),
     (p: 'dbsrc';      c: 'TDataSource'; h: 'data source distributer.'),
     (p: 'dbsrcdbase'; c: 'TTable';      h: 'DBF-Table data source.'),
     (p: 'dbsrcsql';   c: 'TSQL';        h: 'SQL-Query data source.'),
     (p: 'dbsrcmysql'; c: 'TMySQL';      h: 'MySQL-Connection.'),
     (p: 'dbsrcodbc';  c: 'TODBC';       h: 'ODBC-Connection.')
   );

   // --------------------------
   // database access palette :
   // --------------------------
   recordMyIcons_dbNav : Array[0..10] of recordMyIconsStructure = (
     (p: 'tmouse';       c: 'TMouse';        h: 'Mouse Cursor / Selector'),
     (p: 'dbnavedit';    c: 'TDBnavEdit';    h: 'Select record for 
editing.'),
     (p: 'dbnavapply';   c: 'TDBnavApply';   h: 'Apply darabase record 
changes.'),
     (p: 'dbnavfirst';   c: 'TDBnavFirst';   h: 'Jump to first record 
for editing.'),
     (p: 'dbnavprev';    c: 'TDBnavPrev';    h: 'Goto prev record for 
editing.'),
     (p: 'dbnavnext';    c: 'TDBnavNext';    h: 'Goto next record in 
database.'),
     (p: 'dbnavlast';    c: 'TDBnavLast';    h: 'Jump tp last record.'),
     (p: 'dbnavadd';     c: 'TDBnavAdd';     h: 'Appemd a record in 
database.'),
     (p: 'dbnavdel';     c: 'TDBnavDel';     h: 'Delete a record in 
database.'),
     (p: 'dbnavcancel';  c: 'TDBnavCancel';  h: 'Cancel/Abort 
changes/editing.'),
     (p: 'dbnavrefresh'; c: 'TDBnavRefresh'; h: 'Refresh record set.')
   );



diese records verwende ich, um TabSheet's und Button's darzustellen,
die dann auch gleich ohne Mausklickerriki zu verwenden gleiche Werte
haben.

// ----------------------------------------
// add controls to the control-palette ...
// ----------------------------------------
procedure AddControlPalette(
   page: TPageControl;
   name: String;
   carr: Array of recordMyIconsStructure);
var
   left: Integer;
   tabSh: TTabSheet;
   tabTool: TToolBar;
   pageScr: TPageScroller;
   itemArr: Array of TrecordMyIcons;
   i: Integer;
begin
   tabSh := TTabSheet.Create(page);
   tabSh.PageControl := page;
   tabSh.Align   := alClient;
   tabSh.Caption := name;
   tabSh.Visible := true;

   pageScr := TPageScroller.Create(tabSh);
   pageScr.Parent := tabSh;
   pageScr.Align  := alClient;
   pageScr.AutoScroll := false;
   pageScr.Visible := true;

   tabTool := TToolBar.Create(pageScr);
   tabTool.Parent   := pageScr;
   tabTool.AutoSize := true;
   tabTool.Visible  := true;

   tabTool.Align := alNone;
   tabTool.Left  := 0;
   tabTool.Top   := 0;

   tabTool.ButtonWidth  := 55;
   tabTool.ButtonHeight := 48;

   // create standard palette icons:
   SetLength(itemArr,High(carr)+1);
   left := 0;
   for i := High(itemArr) downto 0 do begin
     itemArr[i] := TrecordMyIcons.Create(tabTool);
     tabTool.InsertComponent(itemArr[i]);
     with itemArr[i] do begin
       Parent     := tabTool;
       Align      := alLeft;
       GroupIndex := 1;
       Width      := 55;
       Height     := 48;
       Top        := 0;
       Left       := left;
       Caption    := '';
       Hint       := carr[i].h;
       Glyph      := TBitmap.Create;
       Glyph.LoadFromFile(imageAssetsDir + carr[i].c + '_150.bmp');
     end;
     inc(left,55);
   end;
   itemArr[0].Down := true;
end;


im weiteren Verlauf des Codes verwende ich dann:

   AddControlPalette(PageControl1, 'Stsndard', 
recordMyIcons_Std   );
   AddControlPalette(PageControl1, 'DataBase Controls', 
recordMyIcons_db    );
   AddControlPalette(PageControl1, 'DataBase Source', 
recordMyIcons_dbSrc );
   AddControlPalette(PageControl1, 'DataBase Navigator', 
recordMyIcons_dbNav );


was mir dann die Buttons in der jeweiligen Kategorie erstellt.

Jetzt ddachte ich mir aber, das man ggf. das "AddControlPalettte"
innerhalb einer Schleife verwenden kann, innerhalb dieser dann auf ein
Array zugegriffen wird.
Dann hätte man einen noch dynamischener Programmcode.

Jens

Back to de.comp.lang.delphi.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

array in array Jens Kallup <kallup.jens@web.de> - 2022-02-19 11:24 +0100
  Re: array in array stefan <adresse@ist.invalid> - 2022-02-19 11:53 +0100
    Re: array in array Jens Kallup <kallup.jens@web.de> - 2022-02-19 12:46 +0100
      Re: array in array stefan <adresse@ist.invalid> - 2022-02-19 13:11 +0100
        Re: array in array Jens Kallup <kallup.jens@web.de> - 2022-02-19 13:30 +0100
          Re: array in array stefan <adresse@ist.invalid> - 2022-02-19 16:37 +0100
            Re: array in array Jens Kallup <kallup.jens@web.de> - 2022-02-19 20:01 +0100
              Re: array in array stefan <adresse@ist.invalid> - 2022-02-20 11:22 +0100
                Re: array in array Jens Kallup <kallup.jens@web.de> - 2022-02-20 15:19 +0100
          Re: array in array Alfred Gemsa <gemsa@gmx.de> - 2022-02-19 22:00 +0100
            Re: array in array Jens Kallup <kallup.jens@web.de> - 2022-02-20 14:49 +0100
              Re: array in array "Michael Landenberger" <spamwirdgefiltert@web.de> - 2022-02-22 15:44 +0100
                Re: array in array Jens Kallup <kallup.jens@web.de> - 2022-02-22 16:31 +0100
  Re: array in array "Michael Landenberger" <spamwirdgefiltert@web.de> - 2022-02-19 21:10 +0100

csiph-web