Forum > Beginners

StaticText

(1/1)

gonzo_post:
Hi i have problem.
i write function that extract *.pod file but when i whant send text to StaticText.Caption i have error.


--- Code: ---Hint: Start of reading config file C:\lazarus\fpc\2.6.4\bin\i386-win32\fpc.cfg
Hint: End of reading config file C:\lazarus\fpc\2.6.4\bin\i386-win32\fpc.cfg
Free Pascal Compiler version 2.6.4 [2014/06/14] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling C:\DOCUME~1\ADMINI~1\USTAWI~1\Temp\project1.lpr
Compiling unit1.pas
unit1.pas(47,14) Error: Identifier not found "StaticText3"
unit1.pas(76) Fatal: There were 1 errors compiling module, stopping

--- End code ---

Da code:

--- Code: ---unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
  StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    MenuItem1: TMenuItem;
    ExitItem: TMenuItem;
    OpenDialog1: TOpenDialog;
    OpenItem: TMenuItem;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    StaticText4: TStaticText;
    procedure ExitItemClick(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure OpenItemClick(Sender: TObject);
    procedure StaticText1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    var filename : string;
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

function PODExtract (filename:string) : string;
begin
  StaticText3.Caption := 'TEST'; //ERROR
end;

[..]

procedure TForm1.OpenItemClick(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    filename := OpenDialog1.Filename;
    StaticText3.Caption := filename; //WORK HERE
  end;
end;

end. 
--- End code ---

taazz:
statictext3 is part of TForm1 you can't access it outside the form with out referencing the form it self try changing your function to something like.

--- Code: ---function PODExtract (filename:string; aControl:TStaticText) : string;
begin
  StaticText3.Caption := 'TEST'; //ERROR
end;

--- End code ---
or even better add the function as a method of the form eg

--- Code: ---  TForm1 = class(TForm)
  ......
  private
    { private declarations }
  public
    { public declarations }
    var filename : string;
    function PODExtract (filename:string) : string;
  end;

......
implementation
function TForm1.PODExtract (filename:string) : string;
begin
  StaticText3.Caption := 'TEST'; //ERROR
end;
......

--- End code ---

Leledumbo:
See class scope here: http://www.freepascal.org/docs-html/ref/refse99.html

Navigation

[0] Message Index

Go to full version