delphi E2003 undeclared identifier 'self' - delphi

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;

Related

Generics in Delphi and returning a reference to tlist<class>

I still use Delphi XE4 (newest compiler I use of multiple Delphi compilers) and need a specific workaround for the fact they completely hid FClients in TBasicAction in this version. I connect/disconnect clients runtime while setting enabled/disabled (to avoid flicker with ~100+ actions and ui elements) thus this workaround for XE4:
Here's my naive attempt and simply returning the field.
TmscBasicActionCrack = class(TBasicAction)
end;
{$IFDEF mymsDELPHIXE4}
TmscBasicActionHelper = class helper for TBasicAction
public
function Helper_Get_Private_FClients: TList<System.Classes.TBasicActionLink>;
end;
{$ENDIF}
{$IFDEF mymsDELPHIXE4}
//------------------------------------------------------------------------------
function TmscBasicActionHelper.Helper_Get_Private_FClients: TList<System.Classes.TBasicActionLink>;
begin
Result := Self.FClients;
end;
{$ENDIF}
However, I get error
E2003 Undeclared identifier: TList<>
I must admit I never go around to using generics with Delphi since I initially heard of stability problems + I need to maintain compability with Lazarus/FreePascal.
I am aware the most recent versions Delphi has altered class helpers again, but I am for now mostly interested in getting this to work with Delphi XE4
The error is indicating that the TList<T> type is unknown to the compiler. To use it you must include System.Generics.Collections in your uses clause.

DELPHI XE7 [dcc32 Error] E2250 There is no overloaded version of 'Pos' that can be called with these arguments

DELPHI XE7 on win7 32bit
code:
procedure TForm1.IdMappedPortTCP1Execute(AContext: TIdContext);
begin
if (pos('CONNECT',AContext)<>0) or (pos('GET',AContext)<>0) or (pos('POST',AContext)<>0) or (pos('HEAD',AContext)<>0)
then
(....)
sleep(100);
end;
error:
[dcc32 Error] Unit1.pas(49): E2250 There is no overloaded version of 'Pos' that can be called with these arguments
please help me how to fix that code
thanks in advance
The arguments to Pos are two strings. The functions searches for the first occurrence of a substring (the first parameter) within another string (the second parameter). The function is documented here: http://docwiki.embarcadero.com/Libraries/en/System.Pos
You are passing AContext which is of type TIdContext and that is not a string. To fix the code you need to pass the string that contains the text within which you intend to search.

Use macro codes in Delphi like C/C++

I found this macro code in Delphi/Pascal syntax but i can't use it! Does Delphi support macro codes like C/C++ or this macro is for another language such as Lazarus ???
The macro :
{$ifdef Profile}
{$define __TRACE__:= try }
{$define __END__:= finally ShowMessage('Hello !'); end;}
{$else}
{$define __TRACE__:= //}
{$define __END__:=}
{$endif}
I'm trying to use like this :
...
__TRACE__
// Somethings
__END__
...
I caught this compiler message :
[dcc32 Error] Unit1.pas(37): E2003 Undeclared identifier: '__TRACE__'
[dcc32 Error] Unit1.pas(38): E2066 Missing operator or semicolon
[dcc32 Error] Unit1.pas(39): E2003 Undeclared identifier: '__END__'
{Excuse me if my English is bad}
These are Free Pascal macros. There's nothing at all like this available for the Delphi compiler. Some options:
Use a logging framework (there are many good logging libraries available) to add trace debug facilities to the code. Frankly that would be a huge improvement on what is shown here.
Expand the code manually. That is each time you see __TRACE__ in the code, replace that with an inline $IFDEF. Not appealing at all.

Delphi giving syntax errors: . expected but ; found error

I am toying around in Delphi XE6, and add this procedure on a button:
procedure TTabbedForm.btnLoadingClick(Sender: TObject);
var
dlg: Unit2;
begin
dlg := Form2.Create(nil);
Form2.ShowModal();
end;
Delphi gives me the following error while compiling:
[DCC Error] TabbedTemplate.pas(53): E2029 '.' expected but ';' found
[DCC Error] TabbedTemplate.pas(55): E2029 ';' expected but 'BEGIN' found
[DCC Fatal Error] Speelpleintjes.dpr(7): F2063 Could not compile used unit 'TabbedTemplate.pas'
Line 53 being: dlg: Unit2;
Honestly i'm quite puzzled, the syntax seems correct, the procedure is auto generated from the events tab.
Any suggestions?
If Unit2 is another unit in your project (judging by it's name it probably is), it can't be used as a type directly. Units only declare things. That's why the compiler is expecting a . since you can prefix an identifier with the unit's name to direct to a declaration in that specific unit.
To correct this, write dlg: TForm2;
Also it's common practice to call constructors from the class declaration, not a variable so change it to:
dlg := TForm2.Create(nil);
Or use the Form2 variable, which typically will hold an instance of TForm2 already. By default extra forms added to a Delphi project are created hidden, ready for Show or ShowModal.

Confused by UInt64

The code snippet below demonstrates a problem I am having with with text IO and UInt64 type variables in Delphi XE2 recently re-installed from a recent ISO image file - the compile fails with an error message relating to a missing Text.ReadUInt64 function or procedure. If I replace the failing line with
ReadLn(F,A);
then the program compiles, correctly writes
-1
18446744073709551615
to the text file, and then (as expected) fails on the second read with an EInOutError: "Invalid Numeric Input". Do I have a corrupt install or has someone failed to write a ReadUInt64 function? The only reference to ReadUInt64 that I can find in help is the following definition:
function ReadUInt64: UInt64; virtual;
in System.Classes.TBinaryReader.ReadUInt64. I'm not sure if this is the 'same' function or, if so, why it is virtual...
I am also a little confused by Help's reference to UInt64. It defines it as:
type UInt64 = Int64;
If this is correct, how does the compiler know to treat an UInt64 differently to an Int64 variable?
procedure TForm1.Button1Click(Sender: TObject);
var
F : TextFile;
A : Int64;
B : Uint64;
begin
{
Compiler warns on following line with message:
[DCC Warning] Unit1.pas(32): W1012 Constant expression violates subrange bounds
}
A := $FFFFFFFFFFFFFFFF;
B := $FFFFFFFFFFFFFFFF;
AssignFile(F,'test.txt');
ReWrite(F);
Writeln(F,A);
Writeln(F,B);
CloseFile(F);
AssignFile(F,'test.txt');
ReSet(F);
ReadLn(F,A);
{
Fails to compile on following line with message:
[DCC Fatal Error] Unit1.pas(42): E2158 System unit out of date or corrupted: missing 'Text.ReadUInt64'
}
ReadLn(F,B);
CloseFile(F);
end;
See QC102876. This is a known bug, reported as Text.ReadUInt64 missing, with the description:
The compiler generates a call to Text.ReadUInt64, when an UInt64 should be read from a stream. The linker, however, complains that Text.ReadUInt64 is missing.
This issue (bug) is resolved in XE3 (build #17.0.4625.53395), according to QC.

Resources