G
gz_wh
Unregistered / Unconfirmed
GUEST, unregistred user!
我在写一个调试信息输出类的时候定义了一个全局类,但在程序初始化时,一运行到initialization的初始化部分时就出错了
请帮忙看看是怎么回事
unit Debug;
interface
uses Windows, Classes, SysUtils;
type
TDebug = Class
private
Msgs: TStringList;
public
constructor Create;
destructor Destroy
override;
procedure Add(Msg: string);
procedure Write(Msg: string)
overload;
procedure Write
overload;
end;
var
Debuger: TDebug;
implementation
constructor TDebug.Create;
begin
inherited Create;
Msgs := TStringList.Create;
AllocConsole;
end;
destructor TDebug.Destroy;
begin
FreeConsole;
inherited Destroy;
end;
procedure TDebug.Write(Msg: string);
begin
WriteLn(Msg);
end;
procedure TDebug.Add(Msg: string);
begin
Msgs.Add(Msg);
end;
procedure TDebug.Write;
var
i: integer;
begin
AllocConsole;
for i := 0 to Msgs.Count - 1 do
WriteLn(Msgs);
Msgs.Clear;
end;
initialization
Debuger.Create;
finalization
Debuger.Free;
end.
请帮忙看看是怎么回事
unit Debug;
interface
uses Windows, Classes, SysUtils;
type
TDebug = Class
private
Msgs: TStringList;
public
constructor Create;
destructor Destroy
override;
procedure Add(Msg: string);
procedure Write(Msg: string)
overload;
procedure Write
overload;
end;
var
Debuger: TDebug;
implementation
constructor TDebug.Create;
begin
inherited Create;
Msgs := TStringList.Create;
AllocConsole;
end;
destructor TDebug.Destroy;
begin
FreeConsole;
inherited Destroy;
end;
procedure TDebug.Write(Msg: string);
begin
WriteLn(Msg);
end;
procedure TDebug.Add(Msg: string);
begin
Msgs.Add(Msg);
end;
procedure TDebug.Write;
var
i: integer;
begin
AllocConsole;
for i := 0 to Msgs.Count - 1 do
WriteLn(Msgs);
Msgs.Clear;
end;
initialization
Debuger.Create;
finalization
Debuger.Free;
end.