Einzelnen Beitrag anzeigen

Kas Ob.

Registriert seit: 3. Sep 2023
214 Beiträge
 
#9

AW: Unerklärliche Access Violation

  Alt 7. Sep 2023, 17:16
After thinking, i want to correct my self, the above might not always fail with an exception in fact it could run without any problem,
Delphi-Quellcode:
type
  TMyClass = class
  public
    function DoAdd(A, B: Integer): Integer;
  end;

function TMyClass.DoAdd(A, B: Integer): Integer;
begin
  Result := A + B;
end;

procedure Test1;
var
  C: TMyClass;
begin
  C := TMyClass.Create;
  try
    Writeln(C.DoAdd(5, 7));
  finally
    C.Free;
  end;
end;

procedure Test2;
var
  C: TMyClass;
begin
  //C.Create; not needed at all, with it there will be a memory leak
  Writeln(C.DoAdd(6, 9));
end;

begin
  Test1;
  //Writeln('Soemthing'); // this didn't destroy the stack on my Delphi XE8
  Test2;
  Readln;
end.
The result
Zitat:
12
15
  Mit Zitat antworten Zitat