Sets & FPC

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Sets & FPC

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
 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

cobines
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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

Justin Smyth
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

----- Original Message -----
From: "cobines" <[hidden email]>
To: "Justin Smyth" <[hidden email]>; "FPC-Pascal users
discussions" <[hidden email]>
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
>
>


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

Jonas Maebe-2

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_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

Justin Smyth
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;

----- Original Message -----
From: "Jonas Maebe" <[hidden email]>
To: "Justin Smyth" <[hidden email]>; "FPC-Pascal users
discussions" <[hidden email]>
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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

Michael Van Canneyt


On Sat, 20 Feb 2010, Justin Smyth wrote:

> procedure TJvCustomListBox.CNDrawItem(var Msg: TWMDrawItem);
> var
> State: TOwnerDrawState;

Try

   State : Set of TOwnerDrawState;

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

Jonas Maebe-2

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;


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

Michael Van Canneyt


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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

Justin Smyth
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

----- Original Message -----
From: "Michael Van Canneyt" <[hidden email]>
To: "FPC-Pascal users discussions" <[hidden email]>
Cc: "Justin Smyth" <[hidden email]>
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.
>
>


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

Jonas Maebe-2

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_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

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

I have since looked at CustomListBox.inc 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




----- Original Message -----
From: "Jonas Maebe" <[hidden email]>
To: "Justin Smyth" <[hidden email]>; "FPC-Pascal users
discussions" <[hidden email]>
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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

Jonas Maebe-2

On 21 Feb 2010, at 13:20, 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_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sets & FPC

martin_wynne
In reply to this post by Justin Smyth
Justin Smyth wrote

> 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.



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal