2016-09-17 12 views
0

私はパスカル・ラザロ(Linux)のに問題が生じています:ラザロパスカル - クラスメソッドは、アクセスもできないプライベートメンバーに

クラスメソッドは、メンバーをアクセスもできません。これはコンパイラの間違いではなく、実行時エラーです。 (SIGSEV)

詳細情報:最新のバージョン(16_4)とLazarus Pascal(16.0)のLinuxを使用しています。私のシステムタイプはx86_64の

ですコード:

unit compiler_code; 

{$mode objfpc}{$H+} 

interface 

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

type 

    { TForm1 } 

    TForm1 = class(TForm) 
    Button1: TButton; 
    procedure Button1Click(Sender: TObject); 
    private 
    { private declarations } 
    public 
    { public declarations } 
    end; 

    TLine = class 
     public   //public methods 
       procedure setLine(i: string); //setter for the line. 
       procedure compileLine();  //just runs the different methods of the class 
     private   //private members 
       var m_string  : string; 
       var m_stringLength : integer; 
     private   //private methods 
       function deleteBlanks (i: string) : string; 
       procedure getStringLength(); 
    end; 

var Form1: TForm1; 
var Zeile: TLine; 

implementation 

{ TForm1 } 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
    Zeile.setLine ('Hallo'); 
    Zeile.compileLine(); 
end; 

/////////////////////////Implementation of the Methods of TLine 

procedure TLine.setLine(i: string); //Setter --> no getter needed. 
begin 
    showmessage (i); 
    showmessage (m_string); //here is where the issue comes up 
    //m_string:= i; 
end; 

procedure TLine.compileLine(); //runs all of the Methods. 
begin 
    getStringLength();     // gets the length of the String-input 
    m_string := deleteBLanks(m_string); //deletes all of the blank space inside the String. 
end; 

function TLine.deleteBlanks (i: string) : string; //blankSpace-Deleter 
var isText : boolean = false; //switch, to check, if the momentary Character is text or not. 
var counter: integer = 0; //counts the number of cycles of the loop 
begin 
    while ((counter < m_stringLength) and (not (m_stringLength = 0))) do //the 'Loop' 
    begin 
     if ((m_string[counter] = ' ') and (not(isText))) then 
     begin 
      delete (m_string, counter, 1); //deletes the blank position 
      dec (counter);     //because there is a position less in the string now. 
      getStringLength();    //regenerates the length of the String; 
     end; 
    end; 
end; 

procedure TLine.getStringLength(); 
begin 
    m_stringLength:= length (m_string);   //gets the Length of the String input. 
end; 

{$R *.lfm} 

end. 
+0

読者は画面を見ることができません。どのような**正確な**ラインでエラーが発生し、**正確**エラーメッセージは何ですか?そしてなぜ地球上で文字列の長さを取得するための手続きを使用しますか? – MartynA

+0

1)エラーは、 –

+0

プロシージャTLine.setLine(i:string)で発生します。 //セッター - >ゲッターが必要ありません。 begin showmessage(i); showmessage(m_string); //ここに問題がどこになるか // m_string:= i; end; –

答えて

1

説明は、あなたは、単にクラスTLineのインスタンスを作成していないことを、おそらく、です。 Zeileに割り当てられていないので、デフォルト値のnilのままです。

あなたはZeileを参照しようとする前に、あなたがこれを行う必要があり、インスタンス

Zeile := TLine.Create; 

をインスタンス化する必要があります。インスタンスを終了したら、破棄します。

Zeile.Free; 
+0

が動作します。ありがとうございました。 :) –

関連する問題