Zumindest fühle ich mich unberechtigt angemeckert
Folgende kleine Klasse (Original Copypasta):
Delphi-Quellcode:
unit _uDebugLog;
interface
uses
Classes, SysUtils, DateUtils, SyncObjs;
type
TDebugLog =
class
private
class var FCS: TCriticalSection;
class var FLogFileName:
String;
class procedure SetLogFileName(
const Value:
String);
public
class var Active: Boolean;
class property LogFileName:
String read FLogFileName
write SetLogFileName;
class procedure Log(s:
String);
end;
implementation
{ TDebugLog }
class procedure TDebugLog.Log(s:
String);
var
f: TFileStream;
begin
if not Active
then Exit;
FCS.Enter;
try
s := FormatDateTime('
dd.mm.yyyy hh:nn:ss:zzz', now)+'
: '+s+#13#10;
try
f := TFileStream.Create(FLogFileName, fmOpenReadWrite
or fmShareDenyWrite);
f.Seek(0, soFromEnd);
f.
Write(s[1], Length(s));
finally
f.Free;
end;
finally
FCS.Leave;
end;
end;
class procedure TDebugLog.SetLogFileName(
const Value:
String);
var
fileHandle: Integer;
errorCode: Integer;
begin
FLogFileName := Value;
if not FileExists(FLogFileName)
then
begin
try
fileHandle := FileCreate(FLogFileName);
except
fileHandle := -1;
end;
if fileHandle <> -1
then
FileClose(fileHandle)
else
begin
errorCode := GetLastError;
raise Exception.Create('
Could not create log file "'+FLogFileName+'
". Code: '+IntToStr(errorCode)+'
Message: '+SysErrorMessage(errorCode));
end;
end;
end;
initialization
TDebugLog.FCS := TCriticalSection.Create;
finalization
TDebugLog.FCS.Free;
end.
Kompiliere ich das, errötet die Zeile mit der Deklaration der class property (LogFileName), und der Fehler lautet:
Zitat:
[DCC Fehler] _uDebugLog.pas(16): E2355 Für den Zugriff auf Klasseneigenschaften muss ein Klassenfeld oder eine statische Klassenmethode verwendet werden
Eigentlich bin ich der Meinung, genau dies zu tun. Warum geht das dann nicht? Danke im Voraus für eure Ideen! (Delphi 2007)
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)