Ja so geht das aber nicht, das ist ja gar nicht Thread-Safe ...
Zitat von
mr_emre_d:
Also lieber Larsi
Hier ne nützliche Klasse, die diese Superfunktion beinhaltet
Code:
interface
type
TNeg = Class
private
FNumber: pInteger;
procedure SetNumber(const Value: pInteger);
public
constructor Create(var Number: Integer );
property Number: pInteger Read FNumber Write SetNumber;
procedure Neg;
End;
implementation
constructor TNeg.Create(var Number: Integer );
begin
FNumber := @Number;
Neg;
Free;
end;
procedure TNeg.Neg;
begin
Number^ := -Round(((sqrt(Power(Number^, 2)) * (-6)) / 6) - 2*Succ(Number^ xor
(1 shl Pred(SizeOf(Integer) shl 3) + MAXINT)) );
end;
procedure TNeg.SetNumber(const Value: pInteger);
begin
FNumber := Value;
end;
Und so kann sie verwendet werden:
Code:
var X: IntegeR;
begin
X:= 10;
TNeg.Create(X);
ShowMessage( IntToStr( x ) );
end;
EDIT:
Credits go to DeddyH & Melfin
Thanks for ur help
So kann er das in allen Lebenslagen verwenden ...
Code:
interface
type
TNeg = Class
private
FCS : TCriticalSection;
FNumber: pInteger;
function GetNumber : pInteger;
procedure SetNumber(const Value: pInteger);
public
constructor Create(var Number: Integer );
property Number: pInteger Read GetNumber Write SetNumber;
procedure Neg;
End;
implementation
constructor TNeg.Create(var Number: Integer );
begin
FCS := TCriticalSection.Create;
FNumber := @Number;
Neg;
Free;
end;
procedure TNeg.Neg;
begin
Number^ := -Round(((sqrt(Power(Number^, 2)) * (-6)) / 6) - 2*Succ(Number^ xor
(1 shl Pred(SizeOf(Integer) shl 3) + MAXINT)) );
end;
function TNeg.GetNumber : pInteger;
begin
FCS.Enter;
try
RESULT := FNumber;
finally
FCS.Leave;
end;
end;
procedure TNeg.SetNumber(const Value: pInteger);
begin
FCS.Enter;
try
FNumber := Value;
finally
FCS.Leave;
end;
end;
cu
Oliver
P.S.: Hat einer den Larsi schon mal wieder gesehen ...
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ea 0a 4c 14 0d b6 3a a4 c1 c5 b9
dc 90 9d f0 e9 de 13 da 60)