Recent

Author Topic: IBX 2.7.2, What's wrong with my codes?  (Read 3287 times)

rvk

  • Hero Member
  • *****
  • Posts: 6814
Re: Lazarus 4, What's wrong with my codes?
« Reply #15 on: June 18, 2025, 10:00:28 am »
Yes.
I had to change the SQL and my fieldname to "NAAM" because I have other tables. But other than that... your code works fine (when moving that i := i + 1;
All three showmessage show the field content.

"Lazarus 4.0 (rev lazarus_4_0) FPC 3.2.2 x86_64-win64-win32/win64" with IBX installed through OPM.

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: Lazarus 4, What's wrong with my codes?
« Reply #16 on: June 18, 2025, 10:06:30 am »
Yes.
I had to change the SQL and my fieldname to "NAAM" because I have other tables. But other than that... your code works fine (when moving that i := i + 1;
All three showmessage show the field content.

"Lazarus 4.0 (rev lazarus_4_0) FPC 3.2.2 x86_64-win64-win32/win64" with IBX installed through OPM.
What?

What is firebird version you're used? I am using firebird 5.02 and Lazarus 4 for windows 32, not sure the fpc version, not in front computer right now.

rvk

  • Hero Member
  • *****
  • Posts: 6814
Re: Lazarus 4, What's wrong with my codes?
« Reply #17 on: June 18, 2025, 10:20:26 am »
What is firebird version you're used? I am using firebird 5.02 and Lazarus 4 for windows 32, not sure the fpc version, not in front computer right now.
On this machine I'm still using Firebird 2.5 (although on others 5).
But that shouldn't matter. The IBX version is much more important in this case.

But with both the same Q.FieldByName in the showmessage in two lines together... it should just work. In between those two lines there is nothing for it to get corrupted.

BTW. You say in your code "Show correctly FieldName".
But you probably meant "Show correctly the field CONTENT".
With Q.FieldByName('title').AsString you don't show the FieldName but the content for field "title".

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: Lazarus 4, What's wrong with my codes?
« Reply #18 on: June 18, 2025, 11:31:35 am »
I have change the codes (move i:= i+1)
Code: Pascal  [Select][+][-]
  1. function TForm1.CreateArr(RptId: string;NoOfCol : integer) : StrArray;
  2. var
  3.   Header : array of string;
  4.   i : integer;
  5. begin
  6.   i:=0;
  7.   SetLength(Header, NoOfCol);
  8.  
  9.   Q.SQL.Clear;
  10.   Q.SQL.Add('select title from m_rpt_col where ID_RPT = ' + RptId + ' order by id' );
  11.   ShowMessage(Q.SQL.Text);
  12.   Q.Open;
  13.  
  14.   while not(Q.EOF) do
  15.   begin
  16.     Header[i] := Q.FieldByName('title').AsString;
  17.     ShowMessage('Header : ' + Header[i]); // Show Header :
  18.     ShowMessage(Q.FieldByName('title').AsString); // Show correctly FieldName
  19.     ShowMessage('Field : ' + Q.FieldByName('title').AsString); // Show Field :
  20.     Q.Next;
  21.     i := i+1;
  22.   end;
  23.  
  24.   Result := Header;
  25. end;
  26.  
The result on line 17 & 19 still empty string.

IBX 2.72.1650

Change code on line 16 to
Code: Pascal  [Select][+][-]
  1. Header[i] := 'abc';
Line 17 and 18 showed correct result, line 19 still empty string.

Could it be IBX not compatible with Firebird 5?

Thaddy

  • Hero Member
  • *****
  • Posts: 17477
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: Lazarus 4, What's wrong with my codes?
« Reply #19 on: June 18, 2025, 11:39:44 am »
CASEcase a case of case, maybe?
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

rvk

  • Hero Member
  • *****
  • Posts: 6814
Re: Lazarus 4, What's wrong with my codes?
« Reply #20 on: June 18, 2025, 11:40:23 am »
Could it be IBX not compatible with Firebird 5?
I thought Firebird 5 wasn't a problem for IBX.

Just tried it with LI-V5.0.2.1613 Firebird 5.0 without any problems.

But there are potentially more problems with your code.
Try removing all the Header lines (so the SetLength and the Header := and the showmessage for Header).
Do the two remaining Showmessages give you problems? Probably not.

You do a SetLength(Header, 12) in your code and a while not (Q.EOF) do it could potentially overflow the array.
But you only retrieve one record with one field so that shouldn't be a problem.

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: Lazarus 4, What's wrong with my codes?
« Reply #21 on: June 18, 2025, 11:50:26 am »
Tried with Firebird 3.10, same Lazarus 4 32 for Windows & IBX, problem still exist.

Doubt this error cause by IBX, I think the problem is in Lazarus.

This is sql for test project
Code: Pascal  [Select][+][-]
  1. CREATE TABLE M_RPT_COL
  2. (
  3.   ID INTEGER NOT NULL,
  4.   ID_RPT INTEGER NOT NULL,
  5.   TITLE VARCHAR(60) NOT NULL,
  6.   WD SMALLINT NOT NULL,
  7.   ISTXT BOOLEAN DEFAULT TRUE NOT NULL,
  8.   CONSTRAINT INTEG_602 PRIMARY KEY (ID)
  9. );
  10.  
  11.  
  12. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('120', '2664', 'Code', '15', 'true');
  13. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('121', '2664', 'Counter', '40', 'true');
  14. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('122', '2664', 'Barcode', '30', 'true');
  15. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('123', '2664', 'Brand', '35', 'true');
  16. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('124', '2664', 'Sub Category', '30', 'true');
  17. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('125', '2664', 'Art', '40', 'true');
  18. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('126', '2664', 'Color', '50', 'true');
  19. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('127', '2664', 'Size', '15', 'true');
  20. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('128', '2664', 'Sld', '15', 'false');
  21. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('129', '2664', 'HPP', '20', 'false');
  22. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('130', '2664', 'Total', '25', 'false');
  23. INSERT INTO M_RPT_COL (ID, ID_RPT, TITLE, WD, ISTXT) VALUES ('131', '2664', 'Sls Prc', '20', 'false');
  24.  
  25.  

Installed from lazarus-4.0-fpc-3.2.2-win32.exe

rvk

  • Hero Member
  • *****
  • Posts: 6814
Re: Lazarus 4, What's wrong with my codes?
« Reply #22 on: June 18, 2025, 12:00:01 pm »
Tried with Firebird 3.10, same Lazarus 4 32 for Windows & IBX, problem still exist.

Doubt this error cause by IBX, I think the problem is in Lazarus.
Did you try removing the Header array of string lines yet?


incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: Lazarus 4, What's wrong with my codes?
« Reply #23 on: June 18, 2025, 12:03:55 pm »
Could it be IBX not compatible with Firebird 5?
I thought Firebird 5 wasn't a problem for IBX.

Just tried it with LI-V5.0.2.1613 Firebird 5.0 without any problems.

But there are potentially more problems with your code.
Try removing all the Header lines (so the SetLength and the Header := and the showmessage for Header).
Do the two remaining Showmessages give you problems? Probably not.

You do a SetLength(Header, 12) in your code and a while not (Q.EOF) do it could potentially overflow the array.
But you only retrieve one record with one field so that shouldn't be a problem.
Same problem, everytime string add to a variable, showmessage only showed string value.

rvk

  • Hero Member
  • *****
  • Posts: 6814
Re: Lazarus 4, What's wrong with my codes?
« Reply #24 on: June 18, 2025, 12:05:44 pm »
Same problem, everytime string add to a variable, showmessage only showed string value.
So, you mean this gives you the same problem ?????????
Code: Pascal  [Select][+][-]
  1. function TForm1.CreateArr(RptId: string;NoOfCol : integer) : StrArray;
  2. begin
  3.   Q.SQL.Clear;
  4.   Q.SQL.Add('select title from m_rpt_col where ID_RPT = ' + RptId + ' order by id' );
  5.   ShowMessage(Q.SQL.Text);
  6.   Q.Open;
  7.   while not(Q.EOF) do
  8.   begin
  9.     ShowMessage(Q.FieldByName('title').AsString); // Show correctly FieldName
  10.     ShowMessage('Field : ' + Q.FieldByName('title').AsString); // Show Field :
  11.     Q.Next;
  12.   end;
  13. end;

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: Lazarus 4, What's wrong with my codes?
« Reply #25 on: June 18, 2025, 12:10:16 pm »
Same problem, everytime string add to a variable, showmessage only showed string value.
So, you mean this gives you the same problem ?????????
Code: Pascal  [Select][+][-]
  1. function TForm1.CreateArr(RptId: string;NoOfCol : integer) : StrArray;
  2. begin
  3.   Q.SQL.Clear;
  4.   Q.SQL.Add('select title from m_rpt_col where ID_RPT = ' + RptId + ' order by id' );
  5.   ShowMessage(Q.SQL.Text);
  6.   Q.Open;
  7.   while not(Q.EOF) do
  8.   begin
  9.     ShowMessage(Q.FieldByName('title').AsString); // Show correctly FieldName
  10.     ShowMessage('Field : ' + Q.FieldByName('title').AsString); // Show Field :
  11.     Q.Next;
  12.   end;
  13. end;
Yes
Code: Pascal  [Select][+][-]
  1. function TForm1.CreateArr(RptId: string;NoOfCol : integer) : StrArray;
  2. var
  3.   Header : array of string;
  4.   i : integer;
  5. begin
  6.   i:=0;
  7.   //SetLength(Header, NoOfCol);
  8.  
  9.   Q.SQL.Clear;
  10.   Q.SQL.Add('select title from m_rpt_col where ID_RPT = ' + RptId + ' order by id' );
  11.   //ShowMessage(Q.SQL.Text);
  12.   Q.Open;
  13.  
  14.   while not(Q.EOF) do
  15.   begin
  16.     //Header[i] := 'abc';//Q.FieldByName('title').AsString;
  17.     //ShowMessage('Header : ' + Header[i]); // Show Header :
  18.     ShowMessage(Q.FieldByName('title').AsString); // Show correctly FieldName
  19.     ShowMessage('Field : ' + Q.FieldByName('title').AsString + 'cv'); // Show Field :
  20.     Q.Next;
  21.     i := i+1;
  22.   end;
  23.  
  24.   Result := Header;
  25. end;
  26.  

rvk

  • Hero Member
  • *****
  • Posts: 6814
Re: Lazarus 4, What's wrong with my codes?
« Reply #26 on: June 18, 2025, 12:24:03 pm »
Code: Pascal  [Select][+][-]
  1.     ShowMessage('Field : ' + Q.FieldByName('title').AsString + 'cv'); // Show Field :
  2.  
Does that really only show
Field :
and not
Field : cv
?

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: Lazarus 4, What's wrong with my codes?
« Reply #27 on: June 18, 2025, 12:38:12 pm »
Code: Pascal  [Select][+][-]
  1.     ShowMessage('Field : ' + Q.FieldByName('title').AsString + 'cv'); // Show Field :
  2.  
Does that really only show
Field :
and not
Field : cv
?
Show
Field : cv

Tried lazarus-4.0-fpc-3.2.2-win64.exe in virtual machine, same result, problem!

krolikbest

  • Sr. Member
  • ****
  • Posts: 262
Re: Lazarus 4, What's wrong with my codes?
« Reply #28 on: June 18, 2025, 02:19:02 pm »
I have change the codes (move i:= i+1)
Code: Pascal  [Select][+][-]
  1. function TForm1.CreateArr(RptId: string;NoOfCol : integer) : StrArray;
  2. var
  3.   Header : array of string;
  4.   i : integer;
  5. begin
  6.   i:=0;
  7.   SetLength(Header, NoOfCol);
  8.  
  9.   Q.SQL.Clear;
  10.   Q.SQL.Add('select title from m_rpt_col where ID_RPT = ' + RptId + ' order by id' );
  11.   ShowMessage(Q.SQL.Text);
  12.   Q.Open;
  13.  
  14.   while not(Q.EOF) do
  15.   begin
  16.     Header[i] := Q.FieldByName('title').AsString;
  17.     ShowMessage('Header : ' + Header[i]); // Show Header :
  18.     ShowMessage(Q.FieldByName('title').AsString); // Show correctly FieldName
  19.     ShowMessage('Field : ' + Q.FieldByName('title').AsString); // Show Field :
  20.     Q.Next;
  21.     i := i+1;
  22.   end;
  23.  
  24.   Result := Header;
  25. end;
  26.  


Maybe
Code: Pascal  [Select][+][-]
  1. Header : array of string;
and later in the code
Code: Pascal  [Select][+][-]
  1. SetLength(Header, NoOfCol);
how much is NoOfCol?

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: Lazarus 4, What's wrong with my codes?
« Reply #29 on: June 18, 2025, 02:27:26 pm »
I have change the codes (move i:= i+1)
Code: Pascal  [Select][+][-]
  1. function TForm1.CreateArr(RptId: string;NoOfCol : integer) : StrArray;
  2. var
  3.   Header : array of string;
  4.   i : integer;
  5. begin
  6.   i:=0;
  7.   SetLength(Header, NoOfCol);
  8.  
  9.   Q.SQL.Clear;
  10.   Q.SQL.Add('select title from m_rpt_col where ID_RPT = ' + RptId + ' order by id' );
  11.   ShowMessage(Q.SQL.Text);
  12.   Q.Open;
  13.  
  14.   while not(Q.EOF) do
  15.   begin
  16.     Header[i] := Q.FieldByName('title').AsString;
  17.     ShowMessage('Header : ' + Header[i]); // Show Header :
  18.     ShowMessage(Q.FieldByName('title').AsString); // Show correctly FieldName
  19.     ShowMessage('Field : ' + Q.FieldByName('title').AsString); // Show Field :
  20.     Q.Next;
  21.     i := i+1;
  22.   end;
  23.  
  24.   Result := Header;
  25. end;
  26.  


Maybe
Code: Pascal  [Select][+][-]
  1. Header : array of string;
and later in the code
Code: Pascal  [Select][+][-]
  1. SetLength(Header, NoOfCol);
how much is NoOfCol?
NoOfCol := 12, same as number of records in the table.

 

TinyPortal © 2005-2018