Превед всем. Помогите мне пожалуйста: вижу следующий лог:
/home/hinst/Documents/programming/hinst-pas-lib/theCommon.pas(86,17) Hint: Conversion between ordinals and pointers is not portable
/home/hinst/Documents/programming/hinst-pas-lib/theCommon.pas(151,23) Hint: Local variable "x" does not seem to be initialized
/home/hinst/Documents/programming/hinst-pas-lib/theContainer.pas(1,1) Fatal: Compilation aborted
И что же?? после двух хинтов Compilation aborted
Lazarus=0.9.26.2; fpc=2.2.2
Глюки компилятора
Модератор: Модераторы
и что же? где содержимое файла theContainer.pas?!
может ещё компилятор обновить?
может ещё компилятор обновить?
Вот
Код: Выделить всё
unit theContainer;
{$mode objfpc}
interface
uses
Classes, SysUtils, Contnrs;
type
{ TGComponentContainer }
generic TGComponentContainer<_TheType> = class(TComponent)
constructor Create(const AOwner:TComponent;
const aFreeObjects:boolean);
private
fList:TComponentList;
function getCount: integer;
function getItem(const aIndex:longint):_TheType;
procedure setItem(const aIndex:longint; const aValue:_TheType);
function IsCorrectIdx(const aIndex:integer):boolean;
public
function Add(const aValue:_TheType):integer;
property Items[const aIndex:longint]:_TheType
read getItem write setItem; default;
property Count:integer read getCount;
destructor Destroy; override;
end;
TComponentContainer = specialize TGComponentContainer <TComponent>;
TDataModuleContainer = specialize TGComponentContainer <TDataModule>;
EGTheMatrixException = class(Exception)
end;
{ TGMatrix }
generic TGTheMatrix<TType> = class(TComponent)
constructor Create(const aOwner:TComponent; const aw, ah:integer);
private
type TItems = array of array of TType;
var fw,fh:integer;
var fItems:TItems;
function getItemF(const ax, ay: integer): TType;
procedure setItemF(const ax, ay: integer; const AValue: TType);
public
function CheckRange(const ax, ay:integer):boolean;
function CheckRange(const ap:TPoint):boolean;
function Alloc:boolean;
function Dealloc:boolean;
function SetItem(const ax, ay:integer; const aItem:TType):boolean;
function GetItem(const ap:TPoint):TType;
property Items[const ax, ay:integer]:TType
read getItemF write setItemF; default;
property Width:integer read fw;
property Height:integer read fh;
destructor Destroy; override;
end;
{ TGContainer }
generic TGContainer<TType> = class(TComponent)
constructor Create(aOwner:TComponent); override;
private
fList:array of TType;
fCount:integer;
function getItem(const i: integer): TType;
procedure InitMe;
public
function Add(const aItem:TType):integer;
property count:integer read fCount;
property items[const i:integer]:TType read getItem; default;
end;
implementation
{ TContainer }
constructor TGComponentContainer.Create(const AOwner: TComponent;
const aFreeObjects:boolean);
begin
inherited Create(AOwner);
fList:=TComponentList.create(aFreeObjects);
end;
function TGComponentContainer.getItem(const aIndex: longint): _TheType;
begin
case IsCorrectIdx(aIndex) of
true: result:=_TheType(fList.Items[aIndex]);
false: result:=nil;
end;
end;
function TGComponentContainer.getCount: integer;
begin
result:=fList.Count;
end;
procedure TGComponentContainer.setItem(const aIndex: longint;
const aValue: _TheType);
begin
if IsCorrectIdx(aIndex)
then fList.Items[aIndex]:=aValue;
end;
function TGComponentContainer.IsCorrectIdx(const aIndex: integer): boolean;
begin
result:=(0 < aIndex)and(aIndex <= fList.Count);
end;
function TGComponentContainer.Add(const aValue: _TheType):integer;
begin
result:=fList.Add(aValue);
end;
destructor TGComponentContainer.Destroy;
begin
FreeAndNil(fList);
inherited Destroy;
end;
{ TGMatrix }
constructor TGTheMatrix.Create(const aOwner:TComponent;
const aw, ah: integer);
begin
if (aw < 1)or(ah < 1) then
raise EGTheMatrixException.Create('Error: erroneous width or height');
fw:=aw;
fh:=ah;
Alloc;
end;
function TGTheMatrix.getItemF(const ax, ay: integer): TType;
begin
case CheckRange(ax, ay) of
true: result:=fItems[ax, ay];
false: result:=nil;
end;
end;
procedure TGTheMatrix.setItemF(const ax, ay: integer; const AValue: TType);
begin
if CheckRange(ax, ay) then fItems[ax, ay]:=aValue;
end;
function TGTheMatrix.GetItem(const ap:TPoint):TType;
begin
result:=Items[ap.x, ap.y];
end;
function TGTheMatrix.SetItem(const ax, ay:integer; const aItem:TType):boolean;
begin
result:=CheckRange(ax, ay);
if result then fItems[ax, ay]:=aItem;
end;
function TGTheMatrix.CheckRange(const ax, ay:integer):boolean;
begin
result:=(0 <= ax)and(0 <= ay)and(ax < fw)and(ay < fh);
end;
function TGTheMatrix.CheckRange(const ap:TPoint):boolean;
begin
result:=CheckRange(ap.x, ap.y);
end;
function TGTheMatrix.Alloc:boolean;
var
x:integer;
begin
setLength(fItems, width);
for x:=0 to width-1 do
begin
setLength(fItems[x], height);
end;
{
for x:=0 to width-1 do
begin
for y:=0 to height-1 do
begin
end;
end;
}
end;
function TGTheMatrix.Dealloc:boolean;
var
x:integer;
begin
for x:=0 to width - 1 do
begin
setLength(fItems[x], 0);
end;
setLength(fItems, 0);
end;
destructor TGTheMatrix.Destroy;
begin
Dealloc;
inherited Destroy;
end;
{ TGContainer }
constructor TGContainer.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
InitMe;
end;
procedure TGContainer.InitMe;
begin
setlength(fList, 0);
fCount:=0;
end;
function TGContainer.getItem(const i: integer): TType;
begin
result:=fList[i];
end;
function TGContainer.Add(const aItem: TType): integer;
begin
setLength(fList, length(fList)+1);
fList[fCount]:=aItem;
result:=fCount;
inc(fCount);
end;
end.
1-х. самое время обновить компилятор! до версии 2.2.4 или 2.4.0
2-х. будет ли воспроизводится ошибка в этом коде:
если да, то такое чувство, что в первом байте theContainer.pas лежит какая-то фигня (например BOM Utf8) о которую компилятор спотыкается.
Так или иначе - обновлять! В старых версиях никто ошибки не будет исправлять.
2-х. будет ли воспроизводится ошибка в этом коде:
Код: Выделить всё
uses theContainer;
var
e : EGTheMatrixException;
begin
writeln(e.ClassName);
end.
если да, то такое чувство, что в первом байте theContainer.pas лежит какая-то фигня (например BOM Utf8) о которую компилятор спотыкается.
Так или иначе - обновлять! В старых версиях никто ошибки не будет исправлять.
