The following code compiles and workes using Delphi 5 but not using Delphi 10.1 Berlin;
function CopyTable(const tSource: TwwTable; const Destination: string): DBIResult;
var
pSourceTableName, pDestination: array[0..DBIMAXTBLNAMELEN] of char;
begin
tSource.Open;
StrPCopy(pSourceTableName, tSource.TableName);
StrPCopy(pDestination, Destination);
Result := DbiCopyTable(tSource.DBHandle, False, pSourceTableName, nil, pDestination);
tSource.Close;
end;
Compiler reports [dcc32 Error] SUPPORT1.PAS(3655): E2010 Incompatible types: 'PAnsiChar' and 'array[0..260] of Char' twice.
How do I change it such that it compiles clean and works as intended?
NB. I cannot scrap the BDE at this stage of a large migration.
DbiCopyTable expects AnsiChar, so you should declare both char arrays accordingly.
Related
the code fragment below works fine for DELPHI 10.4 and FMX framework, but does not compile using DELPHI 11 . Error : maReadWrite not defined
[dcc64 Error] ImageUnit.FMX.pas(5340): E2003 Undeclared identifier: 'maReadWrite'
How to solve this issue and how to write code which compiles using DELPHI 10.4 and DELPHI 11 ?
var bit : TBitmap;
begin
if (Bit.Map(TMapAccess.maReadWrite, bitdata1)) then
try
for i := 0 to Bit.width - 1 do
for j := 0 to Bit.height - 1 do
begin
The TMapAccess values that begin with the ma prefix were deprecated before 10.4 to drop the prefix (ie maRead -> Read, maWrite -> Write, maReadWrite -> ReadWrite). You should have gotten compiler warnings about this in 10.4.
The prefixed values were finally removed completely in 11.0 Alexandria.
So, the correct way to write this code for both versions is to simply use the newer non-prefixed value names, eg:
if (Bit.Map(TMapAccess.ReadWrite, bitdata1)) then
When building a program that uses the Graphics32 library (the old 1.9.1 version) with Delphi XE4 (targeting Win32, if it matters), I got the following compiler error:
[dcc32 Error] GR32_LowLevel.pas(1240): E2010 Incompatible >types: 'PPointer' and 'Pointer'
Which is produced by this line:
Registry.RegisterBinding(FID_FILLLONGWORD, ##FillLongWord);
Where RegisterBinding is defined as:
procedure RegisterBinding(FunctionID: Integer; BindVariable: PPointer);
And FillLongword is defined as:
var
FillLongword: procedure(var X; Count: Cardinal; Value: Longword);
How to resolve the compiler error? To my eyes it seems that the syntax is correct, isn't ## means 'pointer of pointer', which is PPointer?
Thanks.
i have a function that returns a function TFunc<Integer> which is reference to function:Integer.
and i have a procedure which takes a function TFunc<Integer> as argument, calls it and prints its result.
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
function GetFunction:TFunc<Integer>;
begin
result := function:Integer begin result := 42 end;
end;
procedure FunctionCall(AFunc:TFunc<Integer>);
var i:Integer;
begin
i := AFunc;
WriteLn(Format('Function Result = %d',[i]));
end;
begin
// FunctionCall(GetFunction); // error
FunctionCall(GetFunction()); // works as excpected
end.
this call (FunctionCall(GetFunction);) results in an error. and the call with () works as excpected.
my question is:
when in delphi do i need brakets to call a function and when not (i thought that i never need them)
or
shouldn't i need them and is it a bug?
i work with delphi xe5 on windows 7 dcc32.
If what you report is correct (and see below for more on that), then you would have found a bug, I believe.
This code:
FunctionCall(GetFunction);
should not compile. Indeed it does not compile when I try to compile it in XE3, XE4, XE5, XE6 and XE7. It does not compile because, in this particular context, the compiler interprets GetFunction as being of type
function: TFunc<Integer>
All above mentioned compilers object with this error message:
[dcc32 Error] E2010 Incompatible types: 'System.SysUtils.TFunc' and 'Procedure'
So, if you have somehow (perhaps with some compiler options), managed to make that code compile then I can only believe that is due to a bug.
You should deal with this by applying the parentheses so that the compiler can understand that you wish to call GetFunction, not refer to it.
FunctionCall(GetFunction());
I need a bit of help; I'm helping a friend port a Delphi app built years back to newer versions of Windows, as it currently only runs on Windows 95.
The code utilises 3rd party libraries from Woll2Woll for DB operations.
One of these libraries generates the error E2003 Undeclared identifier: 'self'.
I've been through a number of sites via Google and with my limited knowledge of Delphi (stemming from my Pascal training about 12 years ago and extrapolating my slightly rusted PHP, BASH, ColdFusion and ASP coding skills), I've run into a brick wall - I'm strapped for time and can't make sense of the info I'm coming across on the web.
The problematic code segment is from the wwwQuery.pas file and looks like this:
{$ifdef wwDelphi3Up}
procedure TwwQuery.OpenCursor(InfoQuery: Boolean);
{$else}
procedure TwwQuery.OpenCursor;
{$endif}
begin
{$ifdef wwDelphi3Up}
inherited OpenCursor(InfoQuery);
{$else}
inherited OpenCursor;
{$endif}
//Modded by Arie
//wwSaveAnswerTable(self, Handle, FAnswerTable);
wwSaveAnswerTable(self, Handle, 'FAnswerTable');
end;
The precise error messages are:
[DCC Error] wwQuery.pas(243): E2003 Undeclared identifier: 'self'
[DCC Error] wwQuery.pas(244): E2029 '.' expected but ';' found
[DCC Fatal Error] wwcommon.pas(285): F2063 Could not compile used unit 'wwQuery.pas'
Line 243 is the 2nd last line, just above the end;
The wwSaveAnswerTable function looks like this:
Function wwSaveAnswerTable(ADataSet: TDBDataSet; AHandle: HDbiCur; tableName: string): boolean;
What must I change the Self parameter to, to stop the compile error?
Thanks a stack.
The problem is related to compiler define wwDelphi3Up or any related up in code.
As you see next error message: [DCC Error] wwQuery.pas(244): E2029 '.' expected but ';' found
Compiler expects end of program, and line wwSaveAnswerTable(self, Handle, 'FAnswerTable'); are not compiled inside OpenCursor method. That's why Self is not defined.
You don't need to change parameter, because for sure will affect functionality.
Try to compile it without defines, if you are not use an ancient version of Delphi:
procedure TwwQuery.OpenCursor(InfoQuery: Boolean);
begin
inherited OpenCursor(InfoQuery);
wwSaveAnswerTable(self, Handle, 'FAnswerTable'); // Here prob FAnswerTable without quotes
end;
this works in Delphi 2009 but in TurboDelphi/BDS2006 I get an error:
[Pascal Error] xxx.pas(117): E2033
Types of actual and formal var
parameters must be identical
...
var
osVerInfo : TOSVersionInfoExW;
i : Integer;
begin
FillChar(osVerInfo, SizeOf(osVerInfo), 0);
osVerInfo.dwOSVersionInfoSize:=SizeOf(TOSVersionInfoExW) ;
if GetVersionExW(osVerInfo) then
...
Seems buggy, but in D2007 (and thus I guess also in D2006) GetVersionExW requires TOSVersionInfoEx as parameter. In D2009 this equals TOSVersionInfoExW, but below D2009 this is equal to TOSVersionInfoExA. You should go well by declaring osVerInfo as TOSVersionInfoEx. This should compile with both versions.