[Solved] Defining multiple classes in TCustomApplication lazarus / 21-General ---------------------------------------------------------------------- nikel · 2025-04-17 05:55 Hello, I'm trying to learn oop and publish some programs that can be easily developed. I tried the code below but got error: External Sigsegv at Application.Run. Here's my code. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; {$mode objfpc}{$H+}{$J-}{$typedaddress on}{$m+} uses  {$IFDEF UNIX}  cthreads,  {$ENDIF}  Classes, SysUtils, CustApp  { you can add units after this }; type   { TMain }   TMain = class(TCustomApplication)  protected    procedure DoRun; override;  public    constructor Create(TheOwner: TComponent); override;    destructor Destroy; override;    procedure WriteHelp; virtual;  end;   type    TSong = class(TMain)    private      FPath: string;    protected      procedure DoRun; override;    public      property Path: string read FPath write FPath;    end;   { TMain } procedure TMain.DoRun;var  ErrorMsg  : string;   S1        : TSong;begin  // quick check parameters  ErrorMsg:=CheckOptions('h', 'help');  if ErrorMsg<>'' then begin    ShowException(Exception.Create(ErrorMsg));    Terminate;    Exit;  end;   // parse parameters  if HasOption('h', 'help') then begin    WriteHelp;    Terminate;    Exit;  end;   { add your program here }   WriteLn(S1.Path);   // stop program loop  Terminate;end; constructor TMain.Create(TheOwner: TComponent);begin  inherited Create(TheOwner);  StopOnException:=True;end; destructor TMain.Destroy;begin  inherited Destroy;end; procedure TMain.WriteHelp;begin  { add your help code here }  writeln('Usage: ', ExeName, ' -h');end; procedure TSong.DoRun;begin  FPath:='/home/user/Desktop/song.mp3';end; var  Application: TMain; {$R *.res} begin  Application:=TMain.Create(nil);  Application.Title:='project1';  Application.Run;  Application.Free;end. How can I fix the error? ---------------------------------------------------------------------- olatov · 2025-04-17 08:25 Hello, You've declared S1 as TSong instance in a var section, but you never actually created an instance (by calling the constructor) before use. This is essential when working with classes - just declaring a variable is not enough. Normally the relevant code might be: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  S1: TSong;begin  { ... }   { add your program here }   S1 := TSong.Create(Nil);  { constructor - always call before use }  S1.DoRun;  WriteLn(S1.Path);  S1.Free;  { destroy the instance when no longer needed }  However, I'm not sure I fully understand what you are actually trying to achieve. For instance, I don't know why you'd want to inherit TSong class from TMain. ---------------------------------------------------------------------- nikel · 2025-04-17 08:35 Thank you for your reply. That helped a lot.