* * *

Recent Posts

Pages: [1] 2 3 ... 10
1
General / Re: Error in conditionals - Lazarus 1.8.0 Win32
« Last post by rvk on Today at 09:02:06 pm »
Quote
I do see your problem. It has to do with using variants in the char() function.
imho char is a type and char() is a typecasting (some purists write Char rather).
Ah, yes, you are correct. Char() is a type and not a function. Chr() would be better.

Although Integer() is also a type and this works correctly:
Code: Pascal  [Select]
  1. Showmessage(integer(xNum + 55).tostring + ' is the same as ' + integer(27 + 55).tostring);
But that's probably because some typecasts do convert correctly (like string() cast etc).

I do see now where the result is coming from:
Code: Pascal  [Select]
  1. var
  2.   xTmp ,xNum: variant;
  3. begin
  4.   xNum := 27;
  5.   xNum := xNum + 55;
  6.   xTmp := char(xNum); // <-- xNum is 82 here so char(xNum) will be 8
  7.   Showmessage(xTmp { 8 } + ' is different from ' + char(27 + 55) { R });

So xNum + 55 is 82. Because this is a variant it is both integer 82 and string 82. But when casting string 82 to a char you'll get the 8 (which is the result of the function).

I do understand why topicstarter got in trouble here (although I wouldn't have used variants at all for this).
2
General / Re: Error in conditionals - Lazarus 1.8.0 Win32
« Last post by WooBean on Today at 08:49:06 pm »
@rvk
Quote
I do see your problem. It has to do with using variants in the char() function.

imho char is a type and char() is a typecasting (some purists write Char rather).
What do you expect doing typecasting char(variant_variable)?

Code below works as spirit of Pascal (language) comanded.

Code: Pascal  [Select]
  1.   var
  2.     xTmp ,xNum: variant;
  3.   begin
  4.     xNum := 27;
  5.     xTmp := chr(xNum + 55); //chr() but not char()!!!
  6.     //Showmessage(xTmp + ' is different from ' + char(27 + 55)); //
  7.     writeln(xTmp + ' is NOT different from ' + chr(27 + 55));
  8.     readln;
  9.   end.
  10.  
Output of this console application is: R is NOT different from R


Anyway, I find once more that "simple" or "stupid" question can teach us a lot.
3
Graphics / Re: Copying images from a Lazarus application
« Last post by HeavyUser on Today at 07:47:08 pm »
I always thought of bitmaps as rows and columns of pixels an pixel/m etc. was something for WYSIWYG applications and the printer.
But you always learn something.
H
so where do you group an office application then if not in WYSIWYG?
4
Have start HTML page read, parsed, href-s extracted.

if start page is like:
Quote
http://www.foo.com/foo1/foo2/

and what I got from href is like

Quote
/foo3/foo4.html

Ok, I know this is absolute:http://www.foo.com/foo3/foo4.html
but how to make this absolute path  programaticaly ? Including all possible stuff like ../../.. and alike

so far using: httpsend, sax_html, dom_html, dom
5
Graphics / Re: Copying images from a Lazarus application
« Last post by hakelm on Today at 06:35:39 pm »
I always thought of bitmaps as rows and columns of pixels an pixel/m etc. was something for WYSIWYG applications and the printer.
But you always learn something.
H
6
General / Re: How to build pas2js
« Last post by molly on Today at 06:09:29 pm »
Thanks, but what is the "trunk checkout"?
Trunk is located here. for checkout, see wikipedia version control common vocabulary.

In short using version control tool to 'download' the most up to date sources from trunk (version 3.1.1 atm)

Quote
Here's what comes up when I do "locate pas2js" on my system:
Those are not up to date sources from trunk, rather those from FPC 3.0.4 release.

See also here in FPC/Lazarus wiki.
7
General / Re: How to build pas2js
« Last post by segfault on Today at 05:38:17 pm »
You need to use make clean all at the top level directory of the trunk checkout plus a make install (probably as root). Anything else requires experience to do.

Thanks, but what is the "trunk checkout"? Here's what comes up when I do "locate pas2js" on my system:

/usr/share/fpcsrc/3.0.4/packages/pastojs/src/fppas2js.pp
/usr/share/fpcsrc/3.0.4/packages/pastojs/tests/testpas2js.lpi
/usr/share/fpcsrc/3.0.4/packages/pastojs/tests/testpas2js.pp
/usr/share/fpcsrc/3.0.4/utils/pas2js
/usr/share/fpcsrc/3.0.4/utils/pas2js/Makefile
/usr/share/fpcsrc/3.0.4/utils/pas2js/Makefile.fpc
/usr/share/fpcsrc/3.0.4/utils/pas2js/dist
/usr/share/fpcsrc/3.0.4/utils/pas2js/fpmake
/usr/share/fpcsrc/3.0.4/utils/pas2js/fpmake.o
/usr/share/fpcsrc/3.0.4/utils/pas2js/fpmake.pp
/usr/share/fpcsrc/3.0.4/utils/pas2js/pas2js.lpi
/usr/share/fpcsrc/3.0.4/utils/pas2js/pas2js.pp
/usr/share/fpcsrc/3.0.4/utils/pas2js/samples
/usr/share/fpcsrc/3.0.4/utils/pas2js/dist/rtl.js
/usr/share/fpcsrc/3.0.4/utils/pas2js/samples/arraydemo.pp
/usr/share/fpcsrc/3.0.4/utils/pas2js/samples/fordemo.pp
/usr/share/fpcsrc/3.0.4/utils/pas2js/samples/fordowndemo.pp
/usr/share/fpcsrc/3.0.4/utils/pas2js/samples/hello.pas
/usr/share/fpcsrc/3.0.4/utils/pas2js/samples/ifdemo.pp
/usr/share/fpcsrc/3.0.4/utils/pas2js/samples/repeatdemo.pp
/usr/share/fpcsrc/3.0.4/utils/pas2js/samples/whiledemo.pp

So which directory do I "make clean install" from?
8
General / Re: Need some Help for RightToLeft TWinControls
« Last post by wp on Today at 05:37:28 pm »
The doublebuffering machinery for Windows has been reworked a few days ago. Please test Lazarus trunk.
9
General / Re: Error in conditionals - Lazarus 1.8.0 Win32
« Last post by Bart on Today at 05:03:43 pm »
OK, totally off-topic, but this really hurts my eyes.

Code: Pascal  [Select]
  1. Function BaseXTable(xNum: Variant; nBase: Extended; lSwStr: Boolean): Variant;  
  2. ...
  3. Begin
  4. ...
  5. If (IsRange(nBase, 2, 252) <> False) Then Begin
  6. If (lSwStr <> True) Then Begin
  7. ...
  8. End;
  9.  

OMG!
I don't even know where to begin here.

IsRange() returns a boolean, why compare it to another boolean, and why "<>False"?
The "<>False" suggests that there are more options than True/False.
Essentially "<>False" is "not False", which of course is "True".

So you want to know if IsRange() returns True.
The proper way to do so is simply:
Code: Pascal  [Select]
  1. If IsRange(nBase, 2, 252) Then Begin

And mutatis mutandis (google that):
Code: Pascal  [Select]
  1. If  not lSwStr Then Begin

[rant]
And no, comparing a Boolean to True or False does NOT make your code better readable.
Also if you do that, you are rather inconsistent, since the expression (ABoolean = False) results in yet another boolean expression, and you seem to have decided that you need to compare a Boolean expression agains either True of False, so to be consistent you should do if ((ABoolean=False)=True), but even this then is a Boolean expression, which, by your standards has to be compared against True or False, so it needs to be extended to (((ABoolean=False)=True)=True), which unfortunately in itself is a Boolean expression, which in all fairness needs to be compared against True or False, so we get ((((ABoolean=False)=True)=True)=True), which of course still is not enough, so
Code: Pascal  [Select]
  1. (((((ABoolean=False)=True)=True)=True)=True)
etc. etc.
And to be absolutely sure that the compiler knows about True and False, you need to start each Boolean expression by
Code: Pascal  [Select]
  1.   if not (True xor False) then FatalError;
Just because, you know, the compiler may be off a bit, or you run fpc on a quantum computer, where a Boolean can be True and False at the same time, or even not True and not False (google Schrödingers cat), and this will screw up the logic of your program, so if you run the program on such a system you must abort it (and preferrably display a message stating that programs compiled with freepascal cannot run on quantum computers, and that the compiler sucks and that this has nothing to do with possible bugs in your code, because, you know, you have decades of experience in designing compilers that run flawlessly, because you are a genius, and you really know the meaning of Boolean expressions and why you always must compare them against absolute True and/or False and ....
[/rant]

Sorry, I got a little bit carried away.

The main point of course is that I sincerely wish you have fun programming, wether this is in Pascal or some other language.
And that you don't mind that some grumpy old man, that sometimes wishes programming was as simple as in the days of Turbo Pascal 3.0, writes grumpy comments in threads you started.

If you feel up to it, please rewrite your Boolean expressions to be a litle more in line with the language you write them in.

Bart
10
General / Re: Error in conditionals - Lazarus 1.8.0 Win32
« Last post by ASerge on Today at 04:37:49 pm »
Code: Pascal  [Select]
  1. //...
  2. If (IsRange(nBase, 2, 252) <> False) Then Begin
  3. If (lSwStr <> True) Then Begin
  4.  If (IsRange(xNum, 0, 9) <> False) Then xTmp := Char(xNum + 48) Else
  5. //...
  6.  
For me, it's easier:
Code: Pascal  [Select]
  1. //...
  2.   if InRange(nBase, 2, 252) then begin
  3.   if not lSwStr then begin
  4.   if InRange(xNum, 0, 9) then xTmp := Char(xNum + 48) else
  5. //...
  6.  
And stop Visual Basic style. Read Coding Guidelines for Lazarus.
My example of your code, if I understand it correctly:
Code: Pascal  [Select]
  1. program Project1;
  2. {$APPTYPE CONSOLE}
  3. {$mode objfpc}
  4.  
  5. uses Math, SysUtils;
  6.  
  7. {$WARN 3177 OFF: Some fields coming after "$1" were not initialized}
  8. const
  9.   CMagicTable: array [1..12] of record
  10.     UpTo: Integer;
  11.     case Add: Integer of
  12.       0: (Direct: Integer);
  13.   end = ( // ordered by UpTo - it is important
  14.    (UpTo:9; Add:48),
  15.    (UpTo:35; Add:55),
  16.    (UpTo:61; Add:61),
  17.    (UpTo:62; Add:0; Direct: 43),
  18.    (UpTo:63; Add:0; Direct: 47),
  19.    (UpTo:196; Add:59),
  20.    (UpTo:202; Add:-106),
  21.    (UpTo:209; Add:-145),
  22.    (UpTo:210; Add:0; Direct: 44),
  23.    (UpTo:220; Add:-178),
  24.    (UpTo:238; Add:-207),
  25.    (UpTo:251; Add:-238));
  26.  
  27. function BaseXTable(xNum: Integer; nBase: Integer): string; overload;
  28. var
  29.   Code: Integer;
  30.   Index: Integer;
  31. begin
  32.   if InRange(nBase, 2, 252) then
  33.   begin
  34.     Code := xNum;
  35.     for Index := Low(CMagicTable) to High(CMagicTable) do
  36.     begin
  37.       if Code <= CMagicTable[Index].UpTo then
  38.       begin
  39.         if CMagicTable[Index].Add <> 0 then
  40.           Inc(Code, CMagicTable[Index].Add)
  41.         else
  42.           Code := CMagicTable[Index].Direct;
  43.         Exit(Chr(Code));
  44.       end;
  45.     end;
  46.   end;
  47.   Result := '*** Error ***';
  48. end;
  49.  
  50. function BaseXTable(const xNum: string; nBase: Integer): string; overload;
  51. var
  52.   S: string;
  53.   Code: Integer;
  54.   Min, Max, Index: Integer;
  55.   Fit: Boolean;
  56. begin
  57.   if InRange(nBase, 2, 252) then
  58.   begin
  59.     S := Trim(xNum);
  60.     if nBase < 36 then
  61.       Code := Ord(UpCase(S[1]))
  62.     else
  63.       Code := Ord(S[1]);
  64.     for Index := Low(CMagicTable) to High(CMagicTable) do
  65.     begin
  66.       if CMagicTable[Index].Add = 0 then
  67.       begin
  68.         if Code = CMagicTable[Index].Direct then
  69.         begin
  70.           Code := CMagicTable[Index].UpTo;
  71.           Break;
  72.         end;
  73.       end
  74.       else
  75.       begin
  76.         Min := CMagicTable[Index].Add;
  77.         Max := CMagicTable[Index].Add + CMagicTable[Index].UpTo;
  78.         if Min <= Max then
  79.           Fit := InRange(Code, Min, Max)
  80.         else
  81.           Fit := InRange(Code, Max, Min);
  82.         if Fit then
  83.         begin
  84.           Dec(Code, CMagicTable[Index].Add);
  85.           Break;
  86.         end;
  87.       end;
  88.     end;
  89.     if Code < nBase then
  90.       Exit(Chr(Code));
  91.   end;
  92.   Result := '*** Error ***';
  93. end;
  94.  
  95. begin
  96.   Writeln(BaseXTable(27, 36));
  97.   Writeln(BaseXTable(BaseXTable(27, 36), 36));
  98.   Readln;
  99. end.

Pages: [1] 2 3 ... 10

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus