[fpc-pascal] Sets & FPC
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 "" how do i get around this ? Justin Smyth ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Sets & FPC
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" 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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Sets & FPC
procedure TJvCustomListBox.CNDrawItem(var Msg: TWMDrawItem); var State: TOwnerDrawState; begin with Msg.DrawItemStruct^ do begin State := TOwnerDrawState(word(itemState and $)); 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" 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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Sets & FPC
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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Sets & FPC
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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: Re[4]: [fpc-pascal] Re: Ido not understand UTF8 in Windows
On Sat, February 20, 2010 01:15, JoshyFun wrote: > Hello Tomas, > > Friday, February 19, 2010, 11:55:39 PM, you wrote: > > TH> No, this can't work that way, otherwise output of any accented > TH> character in one of the Windows codepages would result in the same > TH> error. > > Tested the "wrong" return of stdout: > > code page UTF8 - 65001 en Windows > Length of string: 7 > camión -> Returned written: 6 > > Source code: > - > uses classes,windows; > var > s: ansistring; > OutputStream: TStream; > Begin > Writeln('code page UTF8 - 65001 en Windows'); > OutputStream := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE)); > s:='cami'+#$C3+#$B3+'n'; //camión > writeln('Length of string: ',Length(s)); > writeln(' -> Returned written: ',OutputStream.write(s[1],Length(s))); > OutputStream.free; > End. OK, this seems to be the problem. The underlying Win32 API (WriteFile) is requested to write 7 bytes to a file. However those 7 bytes correspond to only 6 characters in UTF-8, and the Win32 API (apparently) returns the number of written _characters_ rather than the number of written _bytes_. The Windows implementation of do_write (which is an internal wrapper around the platform specific API for writing to a file) currently assumes that the returned number is again number of bytes (equally to the provided parameter), which is OK for simple single byte codepages, but not OK for UTF-8, and it returns this number without any changes. The System routine for file I/O compares the number of bytes requested to be written to the number returned as actually written and they do not match, it is interpreted as an I/O error. Please, post a bug report about this. I guess that fixing it may require little bit more thinking. One simple way to fix it would be just changing the Windows implementation of do_write so that it only checks for an error value returned by WriteFile and if no error is indicated, the original length of buffer is returned regardless of the value returned by WriteFile. However, the information about the actually written _characters_ may be useful in certain cases, so I'm not sure if it isn't better to preserve it somehow and possibly extend implementation for other platforms to also get this value. Tomas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: Re[4]: [fpc-pascal] Re: Ido not understand UTF8 in Windows
On Sat, 20 Feb 2010, Tomas Hajny wrote: On Sat, February 20, 2010 01:15, JoshyFun wrote: Hello Tomas, Friday, February 19, 2010, 11:55:39 PM, you wrote: TH> No, this can't work that way, otherwise output of any accented TH> character in one of the Windows codepages would result in the same TH> error. Tested the "wrong" return of stdout: code page UTF8 - 65001 en Windows Length of string: 7 camión -> Returned written: 6 Source code: - uses classes,windows; var s: ansistring; OutputStream: TStream; Begin Writeln('code page UTF8 - 65001 en Windows'); OutputStream := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE)); s:='cami'+#$C3+#$B3+'n'; //camión writeln('Length of string: ',Length(s)); writeln(' -> Returned written: ',OutputStream.write(s[1],Length(s))); OutputStream.free; End. OK, this seems to be the problem. The underlying Win32 API (WriteFile) is requested to write 7 bytes to a file. However those 7 bytes correspond to only 6 characters in UTF-8, and the Win32 API (apparently) returns the number of written _characters_ rather than the number of written _bytes_. I fail to see how this can be an FPC problem. See http://msdn.microsoft.com/en-us/library/aa365747(VS.85).aspx and http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx For an explanation. It states clearly that the number of bytes is returned. If it does return the number of characters, then that is a bug in the Microsoft call, not in FPC. Michael.___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re[6]: [fpc-pascal] Re: Ido not understand UTF8 in Windows
Hello FPC-Pascal, Saturday, February 20, 2010, 3:21:51 PM, you wrote: MVC> I fail to see how this can be an FPC problem. MVC> See MVC> http://msdn.microsoft.com/en-us/library/aa365747(VS.85).aspx MVC> and MVC> http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx MVC> For an explanation. It states clearly that the number of bytes is returned. MVC> If it does return the number of characters, then that is a bug in the Microsoft call, MVC> not in FPC. Yes, it states that lpNumberOfBytesWritten returns the amount of written _bytes_ which clearly fails in this case, but also states that if return value is non-zero no error happends :-? Rewritting using plain WinAPI outputs: -- code page UTF8 - 65001 en Windows Length of string: 7 camión Retcode: TRUE Returned written bytes: 6 -- uses classes,windows; var s: ansistring; OutputH: THandle; retcode: LongBool; writ: LongWord; Begin Writeln('code page UTF8 - 65001 en Windows'); OutputH := GetStdHandle(STD_OUTPUT_HANDLE); s:='cami'+#$C3+#$B3+'n'; writeln('Length of string: ',Length(s)); retcode:=WriteFile(OutputH,s[1],Length(s),writ,nil); writeln(''); writeln('Retcode: ',retcode,' Returned written bytes: ',writ); End. -- -- Best regards, JoshyFun ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] some new features to delphi prisem
Hello, REM Objects released an interesting document regarding some changes (that looks so much like Ruby) to their Delphi Prisem. For example assignment of a value regarding a condition: x := if Something then 2; y := case Other of bla : 'hello'; foo : 'bye'; baz : 'adius'; end; And more. You can find more in http://blogs.remobjects.com/blogs/mh/2010/02/18/p1116 Ido http://ik.homelinux.org/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: FPC from subversion without root access
Thank you. I have my own compiler - files from another computer - not the ubuntu package. How can I say the Make program where are the files of the compiler? They are in: ~/apps/fpc/bin and ~/apps/fpc/lib 2010/2/18 Marc Weustink : > Osvaldo Filho wrote: >> >> Sorry: >> >> How can I get the FPC subversion installed on my directory? >> >> 1) Download form subversion - Ok > > download them into say ~/fpc/trunk > >> ...) Compile? Create ~/.fpc.cfg? How ? > > then in ~/fpc/trunk dir run: > make all > make install PREFIX=~ FPC_VERSION=2.5.1 > > this will install the compiler in ~/bin ~/lib etc > > then edit ~/.fpc.cfg and add or adjust paths so they point to ~/lib/fpc > > and make a symlink in ~/bin: > ln -s ../lib/fpc/2.5.1/ppc386 > > > Marc > > >> >> Em 18 de fevereiro de 2010 19:36, Osvaldo Filho >> escreveu: >>> >>> Como posso ter o FPC do subversion instalado em meu diretório? >>> 1) Download form subversion - Ok >>> ...) Compile? Create ~/.fpc.cfg? How ? >>> >> ___ >> fpc-pascal maillist - fpc-pas...@lists.freepascal.org >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> > > ___ > fpc-pascal maillist - fpc-pas...@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] some new features to delphi prisem
y := case Other of bla : 'hello'; foo : 'bye'; baz : 'adius'; end; What do you gain with this? Doesn't look much different to case Other of bla : y := 'hello'; foo : y := 'bye'; baz : y := 'adius'; end; ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] some new features to delphi prisem
On Sat, Feb 20, 2010 at 20:01, Jürgen Hestermann wrote: > > > y := case Other of >> bla : 'hello'; >> foo : 'bye'; >> baz : 'adius'; >> end; >> > > What do you gain with this? > Doesn't look much different to > > case Other of > bla : y := 'hello'; > foo : y := 'bye'; > baz : y := 'adius'; > end; > Shorter write imho. > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] some new features to delphi prisem
In our previous episode, ik said: > > > > Shorter write imho. Or something easily marketable to make people upgrade. Not a problem of FPC. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: FPC from subversion without root access
Osvaldo Filho wrote: Thank you. I have my own compiler - files from another computer - not the ubuntu package. How can I say the Make program where are the files of the compiler? They are in: ~/apps/fpc/bin and ~/apps/fpc/lib add ~/apps/fpc/bin to your path ( if you use bash: add the following to your ~/.bach_profile PATH=$HOME/apps/fpc/bin;$PATH ) and add the following lines to your ~/.fpc.cfg -Fu~/apps/fpc/lib/fpc/$fpcversion/units/$fpctarget -Fu~/apps/fpc/lib/fpc/$fpcversion/units/$fpctarget/* -Fu~/apps/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl if you don't have a ~/.fpc.cfg and do have a /etc/fpc.cfg you can add the following as first to your new ~/.fpc.cfg #INCLUDE /etc/fpc.cfg Marc ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Sets & FPC
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 "" heres my code procedure TJvCustomListBox.CNDrawItem(var Msg: TWMDrawItem); var State: TOwnerDrawState; begin with Msg.DrawItemStruct^ do begin State := TOwnerDrawState(word(itemState and $)); 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" 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. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal