Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-02

Sets & FPC

13 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Justin Smyth

I've got a piece of code which uses TOwnerDrawStateType and TBaseOwnerDrawState which is set of TOwnerDrawStateType , if i have on variable called state which is TOwnerDrawStateType how do i do something like this

if odSelected in state then
begin
  // My Code....
end;

i get this error - Error: Incompatible types: got "TOwnerDrawStateType" expected "<enumeration type>"

how do i get around this ?

Justin Smyth

cobines
to Justin Smyth

If state is of type TOwnerDrawStateType then it can have only one value:

var
 state: TOwnerDrawStateType;
...
if odSelected = state then
begin
  // My Code....
end;

If state is a set type of TOwnerDrawStateType then it can have more values:

var
 state: set of TOwnerDrawStateType;
...
if odSelected in state then
begin
  // My Code....
end;

Maybe you meant to declare 'state' as a set.

cobines
Justin Smyth
to cobines

Opps re reading the code it was actually

if (odSelected in State)  then

and state is defined as TOwnerDrawState which points back to -TBaseOwnerDrawState which is a set of TOwnerDrawStateType

Yet i see in TCustomListBox.DrawItem it has something the same -
  if not (odPainted in State) then

Kind Regards

Justin Smyth

Earlier message 37 lines
----- Original Message ----- From: "cobines" To: "Justin Smyth" ; "FPC-Pascal users discussions" Sent: Saturday, February 20, 2010 9:07 PM Subject: Re: [fpc-pascal] Sets & FPC > If state is of type TOwnerDrawStateType then it can have only one value: > > var > state: TOwnerDrawStateType; > ... > if odSelected = state then > begin > // My Code.... > end; > > > If state is a set type of TOwnerDrawStateType then it can have more > values: > > var > state: set of TOwnerDrawStateType; > ... > if odSelected in state then > begin > // My Code.... > end; > > > Maybe you meant to declare 'state' as a set. > > -- > cobines > >
Jonas Maebe
to Justin Smyth
Justin Smyth wrote 5 lines
Opps re reading the code it was actually if (odSelected in State) then and state is defined as TOwnerDrawState which points back to -TBaseOwnerDrawState which is a set of TOwnerDrawStateType

Please post sample code that should compile and that demonstrates the problem.

Jonas

Justin Smyth
to Jonas Maebe
procedure TJvCustomListBox.CNDrawItem(var Msg: TWMDrawItem);
var
  State: TOwnerDrawState;
begin
  with Msg.DrawItemStruct^ do
  begin
    State := TOwnerDrawState(word(itemState and $FFFF));
    Canvas.Handle := hDC;
    Canvas.Font := Font;
    Canvas.Brush := Brush;
    if Integer(itemID) >= 0 then
    begin
      if (odSelected in state) then
      begin
        Canvas.Brush.Color := FSelectedColor;
        Canvas.Font.Color := FSelectedTextColor;
      end;
      if (([odDisabled, odGrayed] * State)  []) or not Enabled then
        Canvas.Font.Color := FDisabledTextColor;
    end;
    if Integer(itemID) >= 0 then
      DrawItem(itemID, rcItem, State)
    else
    begin
      if Background.DoDraw then
      begin
        Perform(WM_ERASEBKGND, Canvas.Handle, 0);
        if (odFocused in State) then
          DrawFocusRect(hDC, rcItem);
      end
      else
      begin
        Canvas.FillRect(rcItem);
        if odFocused in State then
          DrawFocusRect(hDC, rcItem);
      end;
    end;
    Canvas.Handle := 0;
  end;
end;
Earlier message 23 lines
----- Original Message ----- From: "Jonas Maebe" To: "Justin Smyth" ; "FPC-Pascal users discussions" Sent: Saturday, February 20, 2010 10:39 PM Subject: Re: [fpc-pascal] Sets & FPC On 20 Feb 2010, at 12:32, Justin Smyth wrote: > Opps re reading the code it was actually > > if (odSelected in State) then > > and state is defined as TOwnerDrawState which points back > to -TBaseOwnerDrawState which is a set of TOwnerDrawStateType Please post sample code that should compile and that demonstrates the problem. Jonas
Michael Van Canneyt
to Justin Smyth
Justin Smyth wrote
procedure TJvCustomListBox.CNDrawItem(var Msg: TWMDrawItem); var State: TOwnerDrawState;
Try
   State : Set of TOwnerDrawState;

Michael.

Jonas Maebe
to Michael Van Canneyt
Michael Van Canneyt wrote 9 lines
On Sat, 20 Feb 2010, Justin Smyth wrote: > procedure TJvCustomListBox.CNDrawItem(var Msg: TWMDrawItem); > var > State: TOwnerDrawState; Try State : Set of TOwnerDrawState;

It is already a set:

lcltype.pp:  TOwnerDrawState = set of TOwnerDrawStateType;

Jonas

Michael Van Canneyt
to Jonas Maebe
Jonas Maebe wrote 16 lines
On 20 Feb 2010, at 13:15, Michael Van Canneyt wrote: > On Sat, 20 Feb 2010, Justin Smyth wrote: > >> procedure TJvCustomListBox.CNDrawItem(var Msg: TWMDrawItem); >> var >> State: TOwnerDrawState; > > Try > > State : Set of TOwnerDrawState; It is already a set: lcltype.pp: TOwnerDrawState = set of TOwnerDrawStateType;

Indeed.

Well, the code as posted compiles fine here if I define

TWMDrawItem = TLMDrawItems;

Michael.

Justin Smyth
to Michael Van Canneyt

I'm still getting the same errors

I've done the bit Micheal suggest now which i highlight TWMDrawItem it says its comes from TLMDrawItems.

i still get Error: Incompatible types: got "TOwnerDrawStateType" expected "<enumeration type>"

heres my code

procedure TJvCustomListBox.CNDrawItem(var Msg: TWMDrawItem);
var
  State: TOwnerDrawState;
begin
  with Msg.DrawItemStruct^ do
  begin
    State := TOwnerDrawState(word(itemState and $FFFF));
    Canvas.Handle := hDC;
    Canvas.Font := Font;
    Canvas.Brush := Brush;
    if Integer(itemID) >= 0 then
    begin
      if (odSelected in state) then
      begin
        Canvas.Brush.Color := FSelectedColor;
        Canvas.Font.Color := FSelectedTextColor;
      end;
      if (([odDisabled, odGrayed] * State)  []) or not Enabled then
        Canvas.Font.Color := FDisabledTextColor;
    end;
    if Integer(itemID) >= 0 then
      DrawItem(itemID, rcItem, State)
    else
    begin
      if Background.DoDraw then
      begin
        Perform(WM_ERASEBKGND, Canvas.Handle, 0);
        if (odFocused in State) then
          DrawFocusRect(hDC, rcItem);
      end
      else
      begin
        Canvas.FillRect(rcItem);
        if odFocused in State then
          DrawFocusRect(hDC, rcItem);
      end;
    end;
    Canvas.Handle := 0;
  end;
end;

could it be how State is defined causing me the issue ?

Kind Regards

Justin Smyth

Earlier message 38 lines
----- Original Message ----- From: "Michael Van Canneyt" To: "FPC-Pascal users discussions" Cc: "Justin Smyth" Sent: Saturday, February 20, 2010 11:43 PM Subject: Re: [fpc-pascal] Sets & FPC > > > On Sat, 20 Feb 2010, Jonas Maebe wrote: > >> >> On 20 Feb 2010, at 13:15, Michael Van Canneyt wrote: >> >>> On Sat, 20 Feb 2010, Justin Smyth wrote: >>> >>>> procedure TJvCustomListBox.CNDrawItem(var Msg: TWMDrawItem); >>>> var >>>> State: TOwnerDrawState; >>> >>> Try >>> >>> State : Set of TOwnerDrawState; >> >> It is already a set: >> >> lcltype.pp: TOwnerDrawState = set of TOwnerDrawStateType; > > Indeed. > > Well, the code as posted compiles fine here if I define > > TWMDrawItem = TLMDrawItems; > > Michael. > >
Jonas Maebe
to Justin Smyth
Justin Smyth wrote
I've done the bit Micheal suggest now which i highlight TWMDrawItem it says its comes from TLMDrawItems. i still get Error: Incompatible types: got "TOwnerDrawStateType" expected "<enumeration type>"

Can you post the full program somewhere? (or the full sources to another, smaller, program that demonstrates the same problem)

Jonas

Justin Smyth
to Jonas Maebe

The orginal code comes from JVCL , which wont complile under FPC , the actual unit is jvlistbox.pas

I have since and made a few change , basically
not copying ItemState to a variable but directly doing the checking agaist it

procedure TJvCustomListBox.CNDrawItem(var Msg: TLMDrawListItem);
begin
  with Msg.DrawListItemStruct^ do
  begin
    Canvas.Handle := hDC;
    Canvas.Font := Font;
    Canvas.Brush := Brush;
    if Integer(itemID) >= 0 then
    begin
      if odSelected in ItemState then
      begin
        Canvas.Brush.Color := FSelectedColor;
        Canvas.Font.Color := FSelectedTextColor;
      end;
      if (([odDisabled, odGrayed] * ItemState)  []) or not Enabled then
        Canvas.Font.Color := FDisabledTextColor;
    end;
    if Integer(itemID) >= 0 then
      DrawItem(ItemID, Area, ItemState)
    else
    begin
      if Background.DoDraw then
      begin
        Perform(WM_ERASEBKGND, Canvas.Handle, 0);
        if odFocused in ItemState then
          DrawFocusRect(hDC, Area);
      end
      else
      begin
        Canvas.FillRect(Area);
        if odFocused in ItemState then
          DrawFocusRect(hDC, Area);
      end;
    end;
    Canvas.Handle := 0;
  end;
end;

On DrawItem i get this error

Error: Incompatible type for arg no. 3: Got "TBaseOwnerDrawState", expected "TOwnerDrawState"

I'm Using FPC 2.2.4 & Lazarus X64 9.28.2 ( this is the only one i can debug with in X64).

Kind Regards

Earlier message 22 lines
----- Original Message ----- From: "Jonas Maebe" To: "Justin Smyth" ; "FPC-Pascal users discussions" Sent: Sunday, February 21, 2010 8:11 PM Subject: Re: [fpc-pascal] Sets & FPC On 21 Feb 2010, at 07:26, Justin Smyth wrote: > I've done the bit Micheal suggest now which i highlight TWMDrawItem it > says its comes from TLMDrawItems. > > i still get Error: Incompatible types: got "TOwnerDrawStateType" expected > "<enumeration type>" Can you post the full program somewhere? (or the full sources to another, smaller, program that demonstrates the same problem) Jonas
Jonas Maebe
to Justin Smyth
Justin Smyth wrote
The orginal code comes from JVCL , which wont complile under FPC , the actual unit is jvlistbox.pas

Without full source code that compiles rather than uncompilable snippets it takes a lot more time to help you. Please post the full source code that you are trying to compile somewhere and I'm certain that you'll get both an explanation of what was going wrong and a solution in the very next reply.

I'm Using FPC 2.2.4 & Lazarus X64 9.28.2 ( this is the only one i can debug with in X64).

You mean on Win64 (debugging work fine out of the box on Mac OS X/x64 and Linux/x64). See http://forum.lazarus.freepascal.org/index.php/topic,8669.msg41884.html#msg41884 for how to solve the debugging problems on Win64 on 2.4.0.

Jonas

martin_wynne
to Justin Smyth: I've got a piece of code which uses TOwnerDrawStateType and TBaseOwnerDrawState which is…

Justin Smyth wrote

Show quoted text 11 lines
how do I do something like this if odSelected in state then begin // My Code.... end; I get this error - Error: Incompatible types: got "TOwnerDrawStateType" expected " <enumeration type> "

Hi Justin,

I'm sure you have fixed this by now, but for anyone else, the answer is to add *LCLtype* to your *uses* list.

Martin.