Recent

Author Topic: StaticText  (Read 6173 times)

gonzo_post

  • New Member
  • *
  • Posts: 10
StaticText
« on: June 22, 2014, 09:53:24 pm »
Hi i have problem.
i write function that extract *.pod file but when i whant send text to StaticText.Caption i have error.

Code: [Select]
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

Da code:
Code: [Select]
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. 

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: StaticText
« Reply #1 on: June 22, 2014, 10:24:06 pm »
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: [Select]
function PODExtract (filename:string; aControl:TStaticText) : string;
begin
  StaticText3.Caption := 'TEST'; //ERROR
end;
or even better add the function as a method of the form eg
Code: [Select]
  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;
......

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: StaticText
« Reply #2 on: June 24, 2014, 11:36:07 am »

 

TinyPortal © 2005-2018