Forum > General

ShowModal OnCreate error

<< < (2/2)

engine32:
Thank you.
But my trouble is not over yet. Now I want to add a new line to the memo in a separate procedure like in the following:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit unit2; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, testpas; type   { TFrm2 }   TFrm2 = class(TForm)    mTest: TMemo;    procedure FormCreate(Sender: TObject);  private   public   end;  implementation {$R *.lfm} { TFrm2 }procedure pa;begin  mTest.Lines.Add('a');end; procedure TFrm2.FormCreate(Sender: TObject);begin  pa;end; end. 
I get an error saying that it does not know mTest. Adding "self" in front of it does not help either. Any help is much appreciated.

dbannon:
The issue there is that your procedure, pa (you really need to work on your identifier names) is not a class member of the TFrm2 class.  So, it does not know about the TMemo.

Make that procedure a class member (untested) -


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit unit2; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, testpas; type   { TFrm2 }   TFrm2 = class(TForm)    mTest: TMemo;    procedure FormCreate(Sender: TObject);  private    procedure pa;  public   end;  implementation {$R *.lfm} { TFrm2 }procedure TFrm2.pa;begin  mTest.Lines.Add('a');end; procedure TFrm2.FormCreate(Sender: TObject);begin  pa;end;
I have made two changes, firstly, declared pa up in the private section of TForm2's declaration. Second, I have added "TFrm2." in front of "pa" in the implementation. That way, Memo1 and pa, both being in the same class can see each other.

You probably need to have a bit of a read about the class/object syntax.

One suggestion, when posting demos of problems its a great idea to strip it down as you have done, good. But by using the names that the IDE gives these things by default, Unit2, Memo1, makes it easier for other people to see whats happening. (But, obviously, in your real app, give them sensible, descriptive, names).

Davo

Handoko:
Sorry if I couldn't understand the problem. Did OP mean doing this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit2; {$mode objfpc}{$H+} interface uses  Classes, Forms, Controls, StdCtrls; type   { TForm2 }   TForm2 = class(TForm)    Memo1: TMemo;    procedure FormCreate(Sender: TObject);  end; var  Form2: TForm2; implementation {$R *.lfm} { TForm2 } procedure TForm2.FormCreate(Sender: TObject);begin  Memo1.Lines.Add('Testing');end; end.

Navigation

[0] Message Index

[*] Previous page

Go to full version