Fix64ToLongInt Frage

  • 1
  • 2
  • Page 2 of 2
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

Re: Fix64ToLongInt Frage

 · 
Posted: 05.01.2022 - 10:10  ·  #9
Hi Frank.

The order of units is important for visibility. Pascal was designed to allow single pass compiling. So it addresses the first uses clause first. That means for the first unit in the 'uses' list none of the others is visible to it. For the second unit, only the first is visible. For the third, only the first two are visible, and so on.

For that reason, I treat units as I would in Delphi. In each separate unit I add a uses clause that lists all the secondary units I need in that unit. Adding the same secondary unit in the uses clause of multiple units presents no problem to the compiler and ensures that the units are dealt with in the right order.

I hope that makes sense.

@Avra I don't know the answer to your question and the compiler is so complex that it is difficult to check. Sorry.

================================================================================

Die Reihenfolge der Einheiten ist wichtig für die Sichtbarkeit. Pascal wurde entwickelt, um eine Kompilierung in einem Durchgang zu ermöglichen. Deshalb wird die erste uses Klausel zuerst angesprochen. Das bedeutet, daß für die erste Unit in der 'uses' Liste keine der anderen Units sichtbar ist. Für die zweite Unit ist nur die erste sichtbar. Für die dritte sind nur die ersten beiden sichtbar, und so weiter.

Aus diesem Grund behandle ich Units wie in Delphi. In jeder separaten Unit füge ich eine uses-Klausel hinzu, die alle sekundären Units auflistet, die ich in dieser Unit benötige. Das Hinzufügen der gleichen sekundären Unit in der uses-Klausel mehrerer Units stellt für den Compiler kein Problem dar und stellt sicher, dass die Units in der richtigen Reihenfolge behandelt werden.

Ich hoffe, das macht Sinn.

@Avra Ich kenne die Antwort auf Ihre Frage nicht und der Compiler ist so komplex, dass es schwierig ist, das zu überprüfen. Tut mir leid.
TheBeginner
Schreiberling
Avatar
Gender: n/a
Location: Wunsiedel Bayern
Age: 67
Posts: 755
Registered: 06 / 2013
Subject:

Re: Fix64ToLongInt Frage

 · 
Posted: 05.01.2022 - 10:46  ·  #10
Wau .. but first someone has to figure it out.
I only discovered this by accident

Wau.. da muss aber erstmal einer drauf kommen.
Ich habe das nur durch zufall entdeckt


Gruß Frank
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

Re: Fix64ToLongInt Frage

 · 
Posted: 05.01.2022 - 12:12  ·  #11
Hi Frank.

In the manual (docuCompiler) it says

Quote
A uses-clause in a program or a Unit defines the Units which
are used by this module.


Had you followed this advice you would not have had a problem, and indeed in Delphi this is the mandatory way to go. Rather there is a side effect of the way the compiler works in that sometimes you can get away with not following this advice and by putting the uses clause in the main program. I would argue this this side effect is what you discovered by accident, and should not be considered part of the intended design. Therefore the complaint if any, should be that this side effect should be banned. But that would increase the complexity of the compiler and slow it down, as well as rendering countless programs uncompilable, so I do not intend to change it.

=======================================================

Hallo Frank.

Im Handbuch (docuCompiler) heißt es

Quote
Eine uses-Klausel in einem Programm oder einer Unit definiert die Units, die
von diesem Modul verwendet werden
.

Hätten Sie diesen Rat befolgt, hätten Sie kein Problem gehabt, und in der Tat ist dies in Delphi der vorgeschriebene Weg. Vielmehr gibt es einen Nebeneffekt der Arbeitsweise des Compilers, der dazu führt, dass man manchmal davonkommt, wenn man diesen Rat nicht befolgt und die uses-Klausel in das Hauptprogramm einfügt. Ich würde argumentieren, dass dieser Nebeneffekt von Ihnen zufällig entdeckt wurde und nicht als Teil des beabsichtigten Designs betrachtet werden sollte. Daher sollte die Beschwerde, wenn überhaupt, lauten, dass dieser Nebeneffekt verboten werden sollte. Aber das würde die Komplexität des Compilers erhöhen und ihn verlangsamen sowie zahllose Programme unkompilierbar machen, daher habe ich nicht die Absicht, ihn zu ändern.
TheBeginner
Schreiberling
Avatar
Gender: n/a
Location: Wunsiedel Bayern
Age: 67
Posts: 755
Registered: 06 / 2013
Subject:

Re: Fix64ToLongInt Frage

 · 
Posted: 05.01.2022 - 12:22  ·  #12
No Merlin, you shouldn't change anything, I now know how to do it right. But believe me I have searched and searched.
I even wrote a small test program this morning, only with uFix64 and it worked immediately. And then I got the idea to put uFix64 up first

Nein Merlin, du sollst nichts ändern, ich weiß es jetzt wie man es richtig macht. Aber glaube mir ich habe gesucht und gesucht.
Habe heute morgen sogar ein kleines Test Programm geschrieben, nur mit uFix64 und da ging es sofort. Und dann bin ich auf die Idee gekommen uFix64 nach oben als erstes zu setzten
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

Re: Fix64ToLongInt Frage

 · 
Posted: 05.01.2022 - 12:37  ·  #13
Quote
I now know how to do it right.


Actually Frank, I am not sure that you do.

To do it right you should put

Code
Uses
...
uFix64
....


in every unit that uses uFix64.

Otherwise you risk having to forever juggle the order of units in the main program. Doing it the correct way allows the compiler to do the juggling for you.

=========================================================


Quote
Jetzt weiß ich, wie man es richtig macht.


Ehrlich gesagt, Frank, bin ich mir nicht sicher, ob Sie das wissen.

Um es richtig zu machen, sollten Sie

Code
Verwendet
...
uFix64
....


in jeder Einheit, die uFix64 verwendet.

Andernfalls riskieren Sie, dass Sie die Reihenfolge der Units im Hauptprogramm ständig ändern müssen. Wenn Sie es richtig machen, kann der Compiler das Jonglieren für Sie übernehmen.

Regards
TheBeginner
Schreiberling
Avatar
Gender: n/a
Location: Wunsiedel Bayern
Age: 67
Posts: 755
Registered: 06 / 2013
Subject:

Re: Fix64ToLongInt Frage

 · 
Posted: 05.01.2022 - 12:43  ·  #14
Hello Merlin, I have just tested that, yes I understand what you mean, I now also have uFix64 in the unit_var unit and it doesn't matter now
where I write my uFix64 in my main program.
Thanks for your tip.

Greetings Frank
Hallo Merlin, das habe ich gerade getestet, ja ich verstehe es was du meinst, ich habe jetzt auch in der unit unit_var uFix64 drin und es ist jetzt egal
wo ich mein uFix64 in meinen Hauptprogramm hin schreibe.
Danke für deinen Tipp.

Gruß Frank
  • 1
  • 2
  • Page 2 of 2
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 14 · Cache Hits: 14   108   122 · Page-Gen-Time: 0.020589s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI