Compiler ignores missing parenthesis of Exit command - delphi

Why does the Delphi compiler ignore this missing parenthesis?
function Test: Boolean;
begin
Exit(True; // <-- eek! it compiles...
end;
I found some of my code looking like this and first thought that Delphi ignores my unit - but it just ignores this type of syntax error. So now of course I want to know why.

I'm guessing Exit is considered a token unto itself, and as such anything defined within the same scope after Exit is simply ignored by the compiler (since it cannot execute those instructions anyway).

Maybe the compiler is thinking that either
1. There is an Exit by itself, or
2. There is an Exit with a set of parentheses ().
If it doesn't find #2 it goes to #1.

Related

How to make Google Closure Compiler understand the `caches` variable (CacheStorage)?

If I use caches in my service worker code then Google Closure Compiler (launched with the advanced optimizations mode) will tell me :
/var/www/html/perso/otraSite/web/js/sw_viaTypescript.js:79: ERROR - [JSC_UNDEFINED_VARIABLE] > variable caches is undeclared
})(caches);
^^^^^^
1 error(s), 0 warning(s)
A workaround that I use until now is ... I put window.caches so Google Closure Compiler succeeds to compile but if I let that code, browsers will tell me :
sw.js:18 Uncaught ReferenceError: window is not defined
So I replace window.caches by caches in the code compiled by Google Closure Compiler afterwards but ... having to do this every single time is pretty annoying.
Is there a cleaner way to handle it?

declaring a generic type "of a generic type"

Not exactly sure how to pose this question, but using lazarus v1.8.2 I am attempting to define a generic type, using another generic type:
//initial interface
IOtherInterface<T> = interface
function ExampleFunction : T;
end;
//some generic record
TSomething<T> = record
Something : T;
end;
//attempting to further genericize
IOtherSomething<T> = IOtherInterface<TSomething<T>>;
The error I receive is:
Fatal: Syntax error, "," expected but "<" found
I'm using mode delphi as I want to remain compliant for both compilers. I feel pretty confident that I've done this sort of specialization in delphi before, but don't have great access to a professional version to test.
Is this a limitation to on FPC side of things, or perhaps am I missing something? Any help is greatly appreciated
I am not sure what
IOtherSomething<T> = IOtherInterface<TSomething<T>>;
is meant to achieve here. If you are trying to extend the interface you need something like
IOtherSomething<T> = interface(IOtherInterface<TSomething<T>>)
end;
which does compile in Delphi. I don't have Lazarus to test.
If this is not what you are trying to do I will delete the answer.
If it is, I will edit to remove these comments.
Afaik you should still declare IOtherInterface and later specialize it with TSomething .
Generics.Collections works this way (with TPair in the role of TSomething ).
Anyway, FPC fixes has a problem with double specializations, it sees >> or << as shift tokens. This is fixed in trunk

Delphi - Compiler Directives multi lines effects selected IDE error line

I'm wondering why if the compiler directives was typed on multi lines will effects the selected IDE error line.
For example:
{$SETPEFlAGS IMAGE_FILE_DEBUG_STRIPPED or
IMAGE_FILE_LINE_NUMS_STRIPPED or
IMAGE_FILE_LOCAL_SYMS_STRIPPED or
IMAGE_FILE_RELOCS_STRIPPED}
.....
procedure Foo();
begin
WriteLn('1');
WWriteLn('2');
WriteLn('3');
WriteLn('4');
WriteLn('5');
end;
IDE Error
[dcc32 Error] Crypter.dpr(29): E2003 Undeclared identifier: 'WWriteLn'
Inside the source code the selected line is WriteLn('5'); not WWriteLn('2');
But if the compiler directives was typed on this way (one line) :
{$SETPEFlAGS IMAGE_FILE_DEBUG_STRIPPED or IMAGE_FILE_LINE_NUMS_STRIPPED or IMAGE_FILE_LOCAL_SYMS_STRIPPED or IMAGE_FILE_RELOCS_STRIPPED}
Will fix the issue!.
If things are as you say, then this is a defect in the IDE. Report the issue as a bug to Quality Portal.
It's easy to work around the issue. Simply don't use multi-line directives. In this case you can extract the flag into a separate constant and refer to it in the directive.
const
PEFlags = IMAGE_FILE_DEBUG_STRIPPED or
IMAGE_FILE_LINE_NUMS_STRIPPED or
IMAGE_FILE_LOCAL_SYMS_STRIPPED or
IMAGE_FILE_RELOCS_STRIPPED;
{$SETPEFlAGS PEFlags}
The reason I hesitate in the first paragraph is that what you describe would also occur if the linefeeds were incorrect. If your linefeeds are not CR+LF then the IDE gets confused about line numbers. So, it's worth checking that your linefeeds are CR+LF. You could simply re-type the code and the linefeeds will be correct. Typically you get mixed up linefeeds when you paste from another source.

Why does the compiler say "statement expected, but expression of type '<x>' found"?

I googled around and found a way to set the mouse cursor position in Delphi.
Here is my code example:
SetCursorPos(100,100);
It's simple, but not working. Delphi gives me the error
"statement expected,but expression of type 'longbool' found"
I am getting the same error with this command:
PostMessage(wb1.Handle,WM_KEYDOWN, VK_RIGHT,0);
where wb1 is my TWebBrowser component.
Any ideas?
You have probably disabled a feature called "Extended syntax", which (among other things) allows you to use function calls like procedure calls. You can re-enable this feature in the project's options dialog.

Weird error "Type information missing for class Tmyclass"

Getting this error on a call inside the Delphi Initialization section of an Impl unit on a line like.
TAutoObjectFactory.Create(ComServer, TmyClass, Class_myclass, ciMultiInstance, tmApartment);
the type is defined as
Tmyclass = class(TAutoObject, IConnectionPointContainer, Imyclass)
and it results ultimately in a "Runtime error 217 at .... " running it outisde the debugger.
This class is defined in 1 project and works fine. It's blowing up with this error in another project that uses it and it's dependent upon.
Can anyone tell me what to look for? This is code that's been in production for a while but no one's machine was setup to compile it since 01/2009 and I'm doing it the first time in Delphi 7, was Delphi 6 before.
Never mind. I used the Iclass instead of the TClass in my code to get around this.
Thanks.

Resources