Recent

Author Topic: Constand and CASE types do not match  (Read 9613 times)

jmLandsvik

  • New Member
  • *
  • Posts: 29
Constand and CASE types do not match
« on: April 04, 2011, 11:12:51 am »
is the error when executing this code

Code: [Select]
procedure TForm1.DBNavigatorClick(Sender: TObject; Button: TDBNavButtonType);
begin
  with DBNavigator do
  BEGIN
    case Button OF
         nbFirst,
         nbPrior,
         nbNext,
         nbLast,
         nbInsert,
         //nbDelete,
         nbEdit,
         //nbPost,
         nbCancel,
         nbRefresh:
           {$ifDEF _DEBUG_}
             ListBox.Items.Add(GetEnumName(TypeInfo(Button), INTeger(Button)));
               ListBox.ItemIndex := ListBox.Items.Count -1; //WORKS NOT
             //ShowMessage(GetEnumName(TypeInfo(Button), INTeger(Button)));
           {$endIF}
         nbPost,
         nbDelete:
           BEGIN
             Sqlite3Dataset.ApplyUpdates;
             Sqlite3Dataset.Refresh;
             {$ifDEF _DEBUG_}
               ListBox.Items.Add(GetEnumName(TypeInfo(Button), INTeger(Button)));
               ListBox.ItemIndex := ListBox.Items.Count -1 ; //WORKS
               //ShowMessage(GetEnumName(TypeInfo(Button), INTeger(Button)));
             {$endIF}
           end;
    end;
  end;
end;                        

Compilation stops at the LIstBox.ItemIndex := ... line.

The second ListBox.ItemIndex := .... works fine, or IF I put the exact same line above the "with DBNavigator" line, it works...

Is it a bug, or do I do smt. I should not do ? :)

tnx.

regards
Jan Magne
« Last Edit: April 05, 2011, 05:24:01 pm by jmLandsvik »

eny

  • Hero Member
  • *****
  • Posts: 1665
Re: Constand and CASE types do not match
« Reply #1 on: April 04, 2011, 11:35:41 am »
The code fragment is too short to draw any final conclusions.
My crystal ball says you are using this code in an OnClick event method of the DBNavigator.
If so, then you don't need 'with DBNavigator do'.
For my config (see below) it all works as expected.
All posts based on: Win11; stable Lazarus 4_4  (x64) 2026-02-12 (unless specified otherwise...)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12771
  • FPC developer.
Re: Constand and CASE types do not match
« Reply #2 on: April 04, 2011, 11:46:53 am »
Probably dbnavigator also has a property button

jmLandsvik

  • New Member
  • *
  • Posts: 29
Re: Constand and CASE types do not match
« Reply #3 on: April 04, 2011, 11:58:31 am »
UPDATE:
(added the full procedure)

Sorry, the heading of the procedure was missing, and then I added the second ...ItemIndex... line, and THAT worked! ???


tnx. for the replyes so far...

//JM

jmLandsvik

  • New Member
  • *
  • Posts: 29
Re: Constand and CASE types do not match
« Reply #4 on: April 04, 2011, 01:01:57 pm »
The code fragment is too short to draw any final conclusions.
My crystal ball says you are using this code in an OnClick event method of the DBNavigator.
If so, then you don't need 'with DBNavigator do'.
For my config (see below) it all works as expected.

Tnx. for reply Eny...
Yeah, the with ...do was unnessesary...

But the first ...ItemIndex... still says:
Error: Constant and CASE types do not natch.

//JM

eny

  • Hero Member
  • *****
  • Posts: 1665
Re: Constand and CASE types do not match
« Reply #5 on: April 04, 2011, 01:04:07 pm »
add begin...end:
Code: Pascal  [Select][+][-]
  1.   nbRefresh:
  2.     begin
  3.            {$ifDEF _DEBUG_}
  4.              ListBox.Items.Add(GetEnumName(TypeInfo(Button), INTeger(Button)));
  5.                ListBox.ItemIndex := ListBox.Items.Count -1; //WORKS NOT
  6.              //ShowMessage(GetEnumName(TypeInfo(Button), INTeger(Button)));
  7.            {$endIF}
  8.     end;

Probably dbnavigator also has a property button
If it's a TDBNavigator, it hasn't.
All posts based on: Win11; stable Lazarus 4_4  (x64) 2026-02-12 (unless specified otherwise...)

jmLandsvik

  • New Member
  • *
  • Posts: 29
Re: Constand and CASE types do not match
« Reply #6 on: April 04, 2011, 01:57:23 pm »
tnx eny  :D

sure...
the ifdef/endif started with only one line, and then it grew.
got distracted by the begin - end "look"  :-[

Yes, it is a TDBNavigator...

marcov:
Did you mean ....property button,
or, button property?

//JM

 

TinyPortal © 2005-2018