The dumb Delphi questions

I’m thinking as a Delphi 7 programmer with Delphi 11

1/ why can I not use ‘Not’ in - While Not Str[I] in['', ‘/’, ‘-’] do Inc(I);
2/ Why is some type data sizes like Byte, Word not allowed to be used
3/ PreakPoints are set on the left side of the editor and I get a read dot and I can set it gray
But I cannot get the tick in the red dot for debugging uses, so I can get the view > breakpoint windows > breakpoint - window open ok
But I cannot get the tick in the red dot for debugging uses
what is wrong
4/ I put in my code
type
Byte64 = NativeUInt;
// because ‘NativeUInt’ to me is a stupid word

Some answers for you:

  1. The “not” operator takes precedence over the “in” operator, so what your code is effectively saying is:

       While (Not Str[I]) in['', ‘/’, ‘-’] do Inc(I);
    

    Which doesn’t make much sense. What you need to do is to add a set of brackets like so:

       While Not (Str[I] in['', ‘/’, ‘-’]) do Inc(I);
    
  2. I’m not clear on what you’re asking here - can you provide some context? Are you using SizeOf(Byte) etc?

  3. Do you get blue dots on the left hand side when you run the program? Are you running with debugging? Are you compiling in Debug configuration or Release configuration? To get working break points, you need to compile in Debug configuration and Run with Debugging (F9)

  4. NativeUInt is short for Native Unsigned Integer and will be either 4 bytes in size on 32 bit platforms or 8 bytes on 64 bit platforms. NativeUInt is the unsigned equivalent of NativeInt. You could argue that NativeInteger and NativeUnsignedInteger are clearer but they’d be getting a bit long for my taste, but you could define them if you wanted to. Byte64 would be a bad choice in my opinion as it could easily mislead someone into thinking that it was a value storing 64 bytes. On 32 bit platforms, the name would have absolutely no relationship with reality at all.

1 Like

1/ ok I have to make the Boolean question and contain it in brackets because it interferes with the ‘In’ statement - I think I can get that but did not do that in the past with Delphi 7 its must be done to be more defining in the code rather than to the if statement…

2/ Byte
in a procedure
procedure MyProcedure( …)
var
c: byte; // byte is an error and need to use integer or something much bigger -why?
and at the same time
TCusObject = class(TObject)
Protected
FSize: Byte; // this is good and I think stable

3/ Are you compiling in Debug configuration or Release configuration?
what is Debug configuration or Release configuration? with the Delphi menus > run > breakpoints I have options of windows about breakpoints but no configuration controls

4/ I need a Unsigned Integer of 8 bytes or 64 bit on all platforms!!!
this was not available on Delphi 7 just int64 that was always signed is their a QWord or anything like that

That code won’t compile in Delphi 7 at all as the “in” operator only works for ordinal types and not for char values in that version of Delphi.

You shouldn’t be getting a compile error for c: byte; What is the actual error? Can you paste an entire minimal unit that shows this error?

Take a look in the top right corner of the IDE:
image

In that case, you should be using UInt64 - an unsigned 64 bit integer.

While Not (Str[I] in['', ‘/’, ‘-’]) do Inc(I);

Also, with the above code, have you considered what will happen if the string doesn’t contain any of those characters?

While Not I in [1, 2] do Inc(I);

Also FYI, although the above code will compile in both Delphi 7 and 12.1, it’s not going to do what you’re probably expecting it to do - it’ll do a bitwise not on I first and then check to see if it’s in the set.

1 Like

What about

While Not (Ord(Str[I]) in[ord('/'), ord('-')]) do Inc(I);

BTW: I don’t think an empty string '' will ever match a character (or is that meant to be a space?)

That should work for Delphi 7 but isn’t required for more recent versions of Delphi.

You’re right about the empty string not working - the compiler won’t accept it.

‘UInt64 - an unsigned 64 bit integer.’
I did not know of that thanks - what a ‘type’ to make confusion
I would like rename that for my use

I did not think to look their thanks and how do I set it for tracing code and back to compile the final product?

Nicholas Ring

While Not (Ord(Str[I]) in[ord('/'), ord('-')]) do Inc(I);

I understand that code but want you remove the Ord()

This code works with where Str is an AnsiString or a UnicodeString (String)

  While Not CharInSet(Str[i], ['/', '-']) do inc(i);


it still not allowing me to trace?

If it is not stopping on the breakpoint try right clicking on Project1.exe and select “Build”. Then select the run icon again (F9)

yes I tried that and still no tick in the break points and ride right past the break points and you can see its set on the debug setting too

There is no ‘tick’ on a breakpoint.

When you say “ride right past breakpoint” … how do you know?

  • Do you mean you run the program, and it just runs, doesn’t stop?
  • Do you mean it stops on a different breakpoint?

My point is, how do you know the function is being called?

If you’re desperate, then you can add eg writeln('Line 220') for a console app, or showmessage('Line 220')

What is the type of FKeySoFarPtr ?

Is it a class? or a record?

Apart from the breakpoint issue, I have a feeling you might be wanting to do

    FKeySoFarPtr := TKeyPtr_Whatever.Create(False);

It seems like something a bit off might be going on when you are calling the Create method on a Field, passing in the Field as an argument??

Debugging program, press f9 (preferred), or press the correct run icon (Usually the less obvious icon)

Rodger Plant thanks
I was playing yesterday with the build configurations and nothing was happening at all
took my computer of standby after waking up
ticks in red dots and it stops at the break points!!!
I’m in action!!!
why I will never know?

I like the new statement to me - ’ CharInSet() ’ that is my logic to get a Boolean result!!!
But I must remember to bracket after the ‘Not’ statement

I good good answers to me - thanks - you made my day you could say - thanks