Memo1:= Memo2
I don't need parent or owner . Function value must be destroyed right afret function calling. So behaviour of my function is same as all ordinal functions. Does function with tmemo type need Free-ing?
In my code there is no "memo to text" assign. There is "memo to memo". Why this does not work?
Theoretically I can create temporary memo variable (before func's begin-end section) and type result:=tempmemo.text. But such way is more memory-demanding
unit Unit1;{$mode objfpc}{$H+}interfaceuses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, annaunit;type { TForm1 } TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { private declarations } public { public declarations } end;var Form1: TForm1;implementation{$R *.lfm}{ TForm1 }procedure TForm1.Button1Click(Sender: TObject);begin memo1.Text:=funcANNA(edit1.text).text;end;end.
unit annaunit; {$H+} {$IFDEF UNDER_DEBUG} {$R+,Q+,I+} {$ELSE} {$R-,Q-,I-} {$ENDIF} interfaceuses StdCtrls;function funcANNA(const inside: String): TMemo;implementation function funcANNA(const inside: String): TMemo;begin result:=tmemo.create(nil); result.text:=''; result.text:=inside;end; initialization finalization end.
One possibility is to put it in the TForm.OnClose event.
QuoteIn my code there is no "memo to text" assign. There is "memo to memo". Why this does not work?If you still want to use your code, try repainting (call Invalidate) the memo after assignment. Perhaps it's just not updated because class assignment doesn't trigger any painting event.
It works fine. But where must I put free procedure for funcANNA ?
procedure TForm1.Button1Click(Sender: TObject);begin with funcANNA(edit1.text) do try memo1.Text:=text; finally Free; end;end;
Invalidate or RePaint don't make any effect. Does not work.
TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { private declarations } public { public declarations } end;
Did you write that bold declaration above yourself? Better, attach your .lfm (or write its contents here).
QuoteIt works fine. But where must I put free procedure for funcANNA ?Code: [Select]procedure TForm1.Button1Click(Sender: TObject);begin with funcANNA(edit1.text) do try memo1.Text:=text; finally Free; end;end;
Lazarus/FPC is not Java.
Don't use funcANNA, use assignment: http://www.templetons.com/brad/alice/language/language5.html
I have already reached goal, so the issue is settled
unit Unit1; {$mode objfpc}{$H+}interfaceuses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;type { TForm1 } TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; implementation {$I anna.inc} {$R *.lfm} procedure TForm1.Button1Click(Sender: TObject); var memo1 : TMemo; begin memo1 := funcANNA('this works for me...', self); memo1.Parent := Form1; memo1.Left := 15; memo1.Top := 15; memo1.Width := 200; memo1.Height := 50; memo1.Visible := True; end;end.
function funcANNA(const inside:string; AOwner : TComponent):tMemo;begin result := TMemo.Create(AOwner); result.text:=inside;end;
I have put them through pallette in design time.
But if I use create method inside function , free method must be also inside. Or maybe it's better to put create method outside of funcANNA?