ak si pocas behu programu vytvorim napr. memo
with tmemo.Create(self) do
begin
name:=nazov;
...
..
end;
nazov je urceny pocas behu....ako s tym memom mozem pracovat napr. vlozit text pri kliknuti na button ?
Fórum › Delphi
Vytvaranie a pracovanie s komponentou za behu programu

no tak mas to trochu spatne..... dela se to asi nasledovne:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
memo: TMemo;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
memo.Lines.add('pokus');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
memo := TMemo.create(self);
with memo do begin
Parent := form1;
Left := 20;
Top := 10;
end;
end;
end.
pomoci pole.... s memo. zvladas dynamicka pole?
Sid^ píše:#
# ak si pocas behu programu vytvorim napr. memo#
#with tmemo.Create(self) do#
# begin#
# name:=nazov;#
# ...#
# ..#
# end;#
#nazov je urceny pocas behu....ako s tym memom mozem pracovat napr. vlozit text pri kliknuti na button ?
Sid^ píše:#
# nj ale majme predpoklad ze neviem ako sa to memo bude voalt.......a bude ich viac napr 5 jak to vyriesit? (pocet vytvaranych komponent nieje pevny)
no neviem ktory sposob bude lepsi na vyriesenie tohto
Z hlediska pohodlnosti, bych se priklanel k TObjectListu(aspon se neumusis starat o realokaci):
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Contnrs, StdCtrls; // TObjectList
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure MojeProceduraNaKlikMema(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
Mema: TObjectList;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
Mema :=TObjectList.Create;
end;
procedure TForm1.Button1Click(Sender: TObject);
var memo : TMemo;
begin
memo := Tmemo.Create(Self);
memo.Parent := form1;
memo.Top := random(ClientHeight); // jen tak
memo.Left := random(ClientWidth);
memo.Name := 'Memo'+IntToStr(Mema.Count+1);// vygenuruje nazev
memo.OnClick := MojeProceduraNaKlikMema; // jen pro ilustarci - pri kliku na memo vygenuje novou barvu fontu
// pridani
Mema.Add(memo);
end;
procedure TForm1.MojeProceduraNaKlikMema(Sender: TObject);
begin
TMemo(Sender).Font.Color := RGB(random(256), random(256), random(256)); // zmeni barvu fontu
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree; // vsechno uvolni
end;
end.
thx a teraz ak predpokladam ze vygenerovany nazov mema nieviem (to sa urci pocas programu) a chcem snim v programe pracovat ako sa k nemu vratim ? napr. vygeneruju sa mi v programe 3 mema s nazvami napr. text1 text2 tex3 a ja chcem do mem pridavat text,pracovat snimi, jak nato? :)
A co takhle si je zkusit najit?? pisu to z hlavy:
function FindMemoByName(const aList: TObjectList; const aName: String): Integer;
var i: Integer;
begin
Result := -1;
for i:=0 to aList.Count-1 do
if(TMemo(aList[i]).Name = aName) then begin
Result := i;
exit;
end;
end;
Pokud nenajde memo o zadanem nazvu, vrati -1, jinak jeho index v poli.
pridávaj ich do dynamického poľa, a potom k ním vieš pristúpiť...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i,vrch:integer;
pole: array of Tedit;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
setlength(pole,i);
pole[i-1]:=Tedit.Create(self);
pole[i-1].Parent:=Form1;
pole[i-1].left:=20;
pole[i-1].top:=vrch;
inc(i);
vrch:=vrch+20;
Combobox1.items.add(inttostr(i-1));
end;
procedure TForm1.FormShow(Sender: TObject);
begin
i:=1;
vrch:=10;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
pole[combobox1.itemindex].Text:='ahoj';
end;
end.
tu som to síce robil s editom. Do commboboxu sa vždy pridá nová položka pri vytvorení editu a ktorú položku zvolíš, ten edit sa vyplní. Robil som to pre niekoho iného, ale je to v podstate to čo potrebuješ ty.
btw preco pri
procedure TForm1.Button1Click(Sender: TObject);
begin
setlength(pole,i);
pole[i-1]:=Tedit.Create(self);
pole[i-1].Parent:=Form1;
pole[i-1].left:=20;
pole[i-1].top:=vrch;
inc(i);
vrch:=vrch+20;
Combobox1.items.add(inttostr(i-1));
end;
ak do procedury vlozim riadok
pole[i-1].text:='neaky text';
tak to vyhodi chybu, co stym ak potrebujem priamo v tej procedure vlozit text?
teda oznaceneho?. ked som si to skusal tak to slo tak ze som zmenil a pisalo to cervenou zmenil som pomocou colordialog a pokracoval som v pisani inou farbou. Takto to potrebujem :/ bez oznacovania textu proste pokracovat vo vkladani textu ale inou farbou

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Konec běhu programu — založil Polarski
Zrychleni behu programu — založil VeverkaVeveri
Zastaveni behu programu — založil Tom@sQo
Předávání argumentů za běhu programu — založil x-time
Vytvorenie tlacitka za behu programu — založil fero