Revert r38465 #f26e63161d and use typecasts to prevent range errors. Should fix issue #22760

git-svn-id: trunk@38469 -
This commit is contained in:
juha 2012-08-31 22:38:46 +00:00
parent a9fc3bf413
commit 9b6e54b588
6 changed files with 16 additions and 28 deletions

View File

@ -101,7 +101,7 @@ function FileSetDateUTF8(const FileName: String; Age: Longint): Longint;
var var
lft : TFileTime; lft : TFileTime;
begin begin
ADosTimeToWinTime:=DosDateTimeToFileTime(longrec(DosTime).hi,longrec(DosTime).lo,@lft) and ADosTimeToWinTime:=DosDateTimeToFileTime(LongRec(DosTime).hi,LongRec(DosTime).lo,@lft) and
LocalFileTimeToFileTime(lft,Wintime); LocalFileTimeToFileTime(lft,Wintime);
end; end;
var var

View File

@ -164,7 +164,7 @@ begin
LookupRoot.DesignInfo := LeftTopToDesignInfo(Left, Top); LookupRoot.DesignInfo := LeftTopToDesignInfo(Left, Top);
// always fill the whole designer form // always fill the whole designer form
TControl(LookupRoot).SetBounds(0, 0, Width, Height); TControl(LookupRoot).SetBounds(0, 0, Width, Height);
//DebugLn(['TFrameDesignerForm.DoSaveBounds ',Left,',',Top,' ',LazLongRec(LookupRoot.DesignInfo).Lo,',',LongRec(LookupRoot.DesignInfo).hi]); //DebugLn(['TFrameDesignerForm.DoSaveBounds ',Left,',',Top,' ',LongRec(LookupRoot.DesignInfo).Lo,',',LongRec(LookupRoot.DesignInfo).hi]);
end end
else else
if LookupRoot <> nil then if LookupRoot <> nil then

View File

@ -1298,7 +1298,7 @@ begin
// no parent and not a form // no parent and not a form
AControl.SetBounds(0,0,CompWidth,CompHeight); AControl.SetBounds(0,0,CompWidth,CompHeight);
AControl.DesignInfo := LeftTopToDesignInfo(CompLeft, CompTop); AControl.DesignInfo := LeftTopToDesignInfo(CompLeft, CompTop);
//DebugLn(['TCustomFormEditor.CreateComponent ',dbgsName(AControl),' ',LazLongRec(AControl.DesignInfo).Lo,',',LongRec(AControl.DesignInfo).Hi]); //DebugLn(['TCustomFormEditor.CreateComponent ',dbgsName(AControl),' ',LongRec(AControl.DesignInfo).Lo,',',LongRec(AControl.DesignInfo).Hi]);
end; end;
end end
else else

View File

@ -23,7 +23,7 @@ interface
uses uses
Math, Classes, SysUtils, LCLProc, TypInfo, types, Forms, Controls, Math, Classes, SysUtils, LCLProc, TypInfo, types, Forms, Controls,
LCLClasses, ProjectIntf, ComponentEditors, ObjectInspector; ProjectIntf, ComponentEditors, ObjectInspector;
const const
ComponentPaletteImageWidth = 24; ComponentPaletteImageWidth = 24;
@ -241,24 +241,24 @@ end;
function LeftFromDesignInfo(ADesignInfo: LongInt): SmallInt; function LeftFromDesignInfo(ADesignInfo: LongInt): SmallInt;
begin begin
Result := LazLongRec(ADesignInfo).Lo; Result := SmallInt(LongRec(ADesignInfo).Lo);
end; end;
function TopFromDesignInfo(ADesignInfo: LongInt): SmallInt; function TopFromDesignInfo(ADesignInfo: LongInt): SmallInt;
begin begin
Result := LazLongRec(ADesignInfo).Hi; Result := SmallInt(LongRec(ADesignInfo).Hi);
end; end;
function LeftTopToDesignInfo(const ALeft, ATop: SmallInt): LongInt; function LeftTopToDesignInfo(const ALeft, ATop: SmallInt): LongInt;
begin begin
LazLongRec(Result).Lo:=ALeft; LongRec(Result).Lo:=Word(ALeft);
LazLongRec(Result).Hi:=ATop; LongRec(Result).Hi:=Word(ATop);
end; end;
procedure DesignInfoToLeftTop(ADesignInfo: LongInt; out ALeft, ATop: SmallInt); procedure DesignInfoToLeftTop(ADesignInfo: LongInt; out ALeft, ATop: SmallInt);
begin begin
ALeft := LazLongRec(ADesignInfo).Lo; ALeft := SmallInt(LongRec(ADesignInfo).Lo);
ATop := LazLongRec(ADesignInfo).Hi; ATop := SmallInt(LongRec(ADesignInfo).Hi);
end; end;
{ TDesignerMediator } { TDesignerMediator }

View File

@ -40,7 +40,7 @@ var
Temp: LongInt; Temp: LongInt;
begin begin
Temp:=DesignInfo; Temp:=DesignInfo;
LazLongRec(Temp).Lo:=Reader.ReadInteger; LongRec(Temp).Lo:=Word(Reader.ReadInteger);
DesignInfo:=Temp; DesignInfo:=Temp;
end; end;
@ -49,18 +49,18 @@ var
Temp: LongInt; Temp: LongInt;
begin begin
Temp:=DesignInfo; Temp:=DesignInfo;
LazLongRec(Temp).Hi:=Reader.ReadInteger; LongRec(Temp).Hi:=Word(Reader.ReadInteger);
DesignInfo:=Temp; DesignInfo:=Temp;
end; end;
procedure TCustomFrame.WriteDesignLeft(Writer: TWriter); procedure TCustomFrame.WriteDesignLeft(Writer: TWriter);
begin begin
Writer.WriteInteger(LazLongRec(DesignInfo).Lo); Writer.WriteInteger(LongInt(LongRec(DesignInfo).Lo));
end; end;
procedure TCustomFrame.WriteDesignTop(Writer: TWriter); procedure TCustomFrame.WriteDesignTop(Writer: TWriter);
begin begin
Writer.WriteInteger(LazLongRec(DesignInfo).Hi); Writer.WriteInteger(LongInt(LongRec(DesignInfo).Hi));
end; end;
class procedure TCustomFrame.WSRegisterClass; class procedure TCustomFrame.WSRegisterClass;
@ -148,9 +148,9 @@ begin
Ancestor:=TComponent(Filer.Ancestor); Ancestor:=TComponent(Filer.Ancestor);
if Assigned(Ancestor) then Temp:=Ancestor.DesignInfo; if Assigned(Ancestor) then Temp:=Ancestor.DesignInfo;
Filer.Defineproperty('DesignLeft',@ReadDesignLeft,@WriteDesignLeft, Filer.Defineproperty('DesignLeft',@ReadDesignLeft,@WriteDesignLeft,
(LazLongRec(DesignInfo).Lo<>LazLongrec(Temp).Lo)); (LongRec(DesignInfo).Lo<>LongRec(Temp).Lo));
Filer.Defineproperty('DesignTop',@ReadDesignTop,@WriteDesignTop, Filer.Defineproperty('DesignTop',@ReadDesignTop,@WriteDesignTop,
(LazLongRec(DesignInfo).Hi<>LazLongrec(Temp).Hi)); (LongRec(DesignInfo).Hi<>LongRec(Temp).Hi));
end; end;
procedure TCustomFrame.CalculatePreferredSize(var PreferredWidth, procedure TCustomFrame.CalculatePreferredSize(var PreferredWidth,

View File

@ -33,18 +33,6 @@ uses
type type
// SysUtils.LongRec has unsigned Word for Lo and Hi,
// we need a similar record with signed ShortInt
LazLongRec = packed record
case Integer of
{$ifdef FPC_LITTLE_ENDIAN}
0 : (Lo,Hi : ShortInt);
{$else FPC_LITTLE_ENDIAN}
0 : (Hi,Lo : ShortInt);
{$endif FPC_LITTLE_ENDIAN}
1 : (Bytes : Array[0..3] of Byte);
end;
{ TLCLComponent } { TLCLComponent }
TLCLComponent = class(TComponent) TLCLComponent = class(TComponent)