Problem with FPC2.0.2 and windows

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

Problem with FPC2.0.2 and windows

Hans Mårtensson
I decided to improve an old program, I had written for windows, using
FreePascal 1.0.10.
Having downloaded FPC 2.0.2, I wanted to use this version, believing
that the newer is the better.
So I tried to recompile my old source code with 2.0.2, getting a lot of
compile errors.
Anyhow, all of them could be tracked down to 3 problems with call of
procedures in the windows unit, and the two of them could easily be
repaired. But I have problems with the last one.

The problem was the following program line, using the windows unit:
if DialogBoxIndirect(0, pBox2, Window, @Box2Proc) = 0 then exit;
The compiler assessed an error in parameter 4. Should not be an address,
but a variable.

So I tried:
if DialogBoxIndirect(0, pBox2, Window, Box2Proc) = 0 then exit;
And the compiler assessed that the number of parameters was wrong.
But this is an error in message, because the number of parameters is right.

Then I tried to define a procedural type TBoxproc and then declared a
variable:
var BoxProc: TBoxproc;

and changed my program to:
BoxProc:=@Box2Proc;
if DialogBoxIndirect(0, pBox2, Window, BoxProc)=0 then exit;

Now FPC compiled my program to the end.

BUT following problems remains:
1) I don’t understand why it should be necessary to use a variable that
is assigned to @Box2Proc, in stead of using @Box2Proc directly as the
parameter.

2) Even though the compiler produces an exe file, this does not work.
The call of DialogBoxIndirect does not produce any dialogue box, but
returns having done nothing. Now it is a bit tricky to make this
dialogue box business work, because pBox2 must point to a data
structure, and if there are errors in this data structure, windows do
not produce any error message. But in this case, my data structure
worked with the old version of FPC. I have tried to compile exactly the
same source files with compiler 1.0.10 and with 2.0.2. The first program
worked all right, but the second did not show any dialogue box, when the
procedure in question was invoked.

So I suspect that the compiler or the windows unit that comes with the
2.0.2 version has some error.
Does anybody know about these problems?

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

Re: Problem with FPC2.0.2 and windows

Jonas Maebe-2

On 28 Dec 2005, at 23:49, Hans Mårtensson wrote:

> The problem was the following program line, using the windows unit:
> if DialogBoxIndirect(0, pBox2, Window, @Box2Proc) = 0 then exit;
> The compiler assessed an error in parameter 4. Should not be an  
> address, but a variable.

Is your Box2Proc procedure declared as stdcall? In FPC 1.x, the  
default calling convention was compatible with stdcall, but in 2.x  
this is no longer the case.

> So I tried:
> if DialogBoxIndirect(0, pBox2, Window, Box2Proc) = 0 then exit;
> And the compiler assessed that the number of parameters was wrong.
> But this is an error in message, because the number of parameters  
> is right.

It was probably complaining that too few parameters were specified to  
Box2Proc, not to DialogBoxIndirect. I guess from this that you are  
working in either fpc or objfpc mode.

> Then I tried to define a procedural type TBoxproc and then declared  
> a variable:
> var BoxProc: TBoxproc;

How is TBoxProc defined?

> and changed my program to:
> BoxProc:=@Box2Proc;
> if DialogBoxIndirect(0, pBox2, Window, BoxProc)=0 then exit;
>
> Now FPC compiled my program to the end.

This is the declaration of DialogBoxIndirect:

function DialogBoxIndirect(hInstance:HINST;  
hDialogTemplate:LPCDLGTEMPLATE; hWndParent:HWND;  
lpDialogFunc:DLGPROC):longint;

This is the declaration of DLGPROC:

DLGPROC = function (_para1:HWND; _para2:UINT; _para3:WPARAM;  
_para4:LPARAM):LRESULT;stdcall;

As long as the definition of Box2Proc is compatible with this, there  
should be no problem.

> BUT following problems remains:
> 1) I don’t understand why it should be necessary to use a variable  
> that is assigned to @Box2Proc, in stead of using @Box2Proc directly  
> as the parameter.

It shouldn't be. Please always supply a fully compilable (or non-
compilable in this case, but in any case *complete*) sample if you  
want us to investigate.

> 2) Even though the compiler produces an exe file, this does not  
> work. The call of DialogBoxIndirect does not produce any dialogue  
> box, but returns having done nothing. Now it is a bit tricky to  
> make this dialogue box business work, because pBox2 must point to a  
> data structure, and if there are errors in this data structure,  
> windows do not produce any error message. But in this case, my data  
> structure worked with the old version of FPC. I have tried to  
> compile exactly the same source files with compiler 1.0.10 and with  
> 2.0.2. The first program worked all right, but the second did not  
> show any dialogue box, when the procedure in question was invoked.
>
> So I suspect that the compiler or the windows unit that comes with  
> the 2.0.2 version has some error.
> Does anybody know about these problems?

The most likely reason is that your callback is not declared as  
stdcall. But then the compiler should complain that the calling  
conventions don't match, and not say that it "Should not be an  
address, but a variable" (btw, what is the exact error message you  
get since this error does not exist). And you should not be able to  
circumvent calling convention requirements by using a procvar, as  
procvars also have a calling convention associated with them (so that  
would be a bug in the compiler if you can do that nevertheless).


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

Re: Problem with FPC2.0.2 and windows

Hans Mårtensson-2
Jonas Maebe wrote:

>
> On 28 Dec 2005, at 23:49, Hans Mårtensson wrote:
>
>> The problem was the following program line, using the windows unit:
>> if DialogBoxIndirect(0, pBox2, Window, @Box2Proc) = 0 then exit;
>> The compiler assessed an error in parameter 4. Should not be an  
>> address, but a variable.
>
>
> Is your Box2Proc procedure declared as stdcall? In FPC 1.x, the  
> default calling convention was compatible with stdcall, but in 2.x  
> this is no longer the case.


It is declared as stdcall ... and it was so when using ver. 1.0.10.

>> So I tried:
>> if DialogBoxIndirect(0, pBox2, Window, Box2Proc) = 0 then exit;
>> And the compiler assessed that the number of parameters was wrong.
>> But this is an error in message, because the number of parameters  is
>> right.
>
>
> It was probably complaining that too few parameters were specified to  
> Box2Proc, not to DialogBoxIndirect. I guess from this that you are  
> working in either fpc or objfpc mode.


I had that option in my mind too, but the number of parameters in
Box2Proc is also correct.
I use the fpc compiler on a source code written in the CrEdit program. I
have not changed the configuration file that comes with the FreePascal
download (except for file location of units).
The only compiler directive I have used in the program is the {$APPTYPE GUI}

>> Then I tried to define a procedural type TBoxproc and then declared  
>> a variable:
>> var BoxProc: TBoxproc;
>
>
> How is TBoxProc defined?

Here is the definition that I used:
Type TBoxProc = Function(x: longword; y: longword; a: longint; b:
longint): longint; stdcall;

>> and changed my program to:
>> BoxProc:=@Box2Proc;
>> if DialogBoxIndirect(0, pBox2, Window, BoxProc)=0 then exit;
>>
>> Now FPC compiled my program to the end.
>
>
> This is the declaration of DialogBoxIndirect:
>
> function DialogBoxIndirect(hInstance:HINST;  
> hDialogTemplate:LPCDLGTEMPLATE; hWndParent:HWND;  
> lpDialogFunc:DLGPROC):longint;
>
> This is the declaration of DLGPROC:
>
> DLGPROC = function (_para1:HWND; _para2:UINT; _para3:WPARAM;  
> _para4:LPARAM):LRESULT;stdcall;
>
> As long as the definition of Box2Proc is compatible with this, there  
> should be no problem.


I cannot see any problem here.
But where are these definitions, I cannot find them in the FPC download,
should they be downloaded separately?
Are they exactly the same as the definitions in the Microsoft documentation?


>> BUT following problems remains:
>> 1) I don’t understand why it should be necessary to use a variable  
>> that is assigned to @Box2Proc, in stead of using @Box2Proc directly  
>> as the parameter.
>
>
> It shouldn't be. Please always supply a fully compilable (or non-
> compilable in this case, but in any case *complete*) sample if you  
> want us to investigate.


Yes of course. I only hoped that someone could point out some simple
mistake I had made, or, inform me that there were some known problem
with the compiler.
The problem is that my program is large with many units that depends on
each other, so it was not easy to pick out the part that invoked the error.
Also it seemed very strange to me that the source code after some
changes could be compiled with both FPC 1.0.10 AND FPC 2.0.2 and both
exe files worked, except for that the FPC 2.0.2 version did not show the
dialog boxes.
Now, I will try to construct a simple program that can reproduce the
problems.

>> 2) Even though the compiler produces an exe file, this does not  
>> work. The call of DialogBoxIndirect does not produce any dialogue  
>> box, but returns having done nothing. Now it is a bit tricky to  make
>> this dialogue box business work, because pBox2 must point to a  data
>> structure, and if there are errors in this data structure,  windows
>> do not produce any error message. But in this case, my data  
>> structure worked with the old version of FPC. I have tried to  
>> compile exactly the same source files with compiler 1.0.10 and with  
>> 2.0.2. The first program worked all right, but the second did not  
>> show any dialogue box, when the procedure in question was invoked.
>>
>> So I suspect that the compiler or the windows unit that comes with  
>> the 2.0.2 version has some error.
>> Does anybody know about these problems?
>
>
> The most likely reason is that your callback is not declared as  
> stdcall. But then the compiler should complain that the calling  
> conventions don't match, and not say that it "Should not be an  
> address, but a variable" (btw, what is the exact error message you  
> get since this error does not exist). And you should not be able to  
> circumvent calling convention requirements by using a procvar, as  
> procvars also have a calling convention associated with them (so that  
> would be a bug in the compiler if you can do that nevertheless).

I tried to omit the stdcall, which made the compiler produce an error
message (something like: wrong format of procedure)


Thank you for your careful answer. I will return later if I am able to
make a simple sample program that can reproduce the problem.
(Or may be I should stick to 1.0.10 that worked for me)

Hans Mårtensson

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

Re: Problem with FPC2.0.2 and windows

Jonas Maebe-2

On 03 Jan 2006, at 19:57, Hans Mårtensson wrote:

>>> So I tried:
>>> if DialogBoxIndirect(0, pBox2, Window, Box2Proc) = 0 then exit;
>>> And the compiler assessed that the number of parameters was wrong.
>>> But this is an error in message, because the number of  
>>> parameters  is right.
>>
>> It was probably complaining that too few parameters were specified  
>> to  Box2Proc, not to DialogBoxIndirect. I guess from this that you  
>> are  working in either fpc or objfpc mode.
>
> I had that option in my mind too, but the number of parameters in  
> Box2Proc is also correct.

What I mean is that in the above snippet (when compiled in fpc/objfpc  
mode), you are calling Box2Proc and passing the result of that call  
as last parameter to DialogBoxIndirect. Since Box2Proc requires 4  
parameters and you didn't supply any, the compiler complains that you  
didn't supply enough parameters.

> I use the fpc compiler on a source code written in the CrEdit  
> program. I have not changed the configuration file that comes with  
> the FreePascal download (except for file location of units).
> The only compiler directive I have used in the program is the  
> {$APPTYPE GUI}

Then you are working in fpc mode.

>> This is the declaration of DialogBoxIndirect:
>>
>> function DialogBoxIndirect(hInstance:HINST;  
>> hDialogTemplate:LPCDLGTEMPLATE; hWndParent:HWND;  
>> lpDialogFunc:DLGPROC):longint;
>>
>> This is the declaration of DLGPROC:
>>
>> DLGPROC = function (_para1:HWND; _para2:UINT; _para3:WPARAM;  
>> _para4:LPARAM):LRESULT;stdcall;
>>
>> As long as the definition of Box2Proc is compatible with this,  
>> there  should be no problem.
>
> I cannot see any problem here.
> But where are these definitions, I cannot find them in the FPC  
> download, should they be downloaded separately?

They are in the sources of the RTL. The above ones are in rtl/win32/
wininc/ascdef.inc. The sources are available from http://
www.freepascal.org/down/source/sources.html

> Are they exactly the same as the definitions in the Microsoft  
> documentation?

They should be.

> Thank you for your careful answer. I will return later if I am able  
> to make a simple sample program that can reproduce the problem.
> (Or may be I should stick to 1.0.10 that worked for me)

It would be nice if you could provide the sample program (and submit  
it as a bugreport at http://www.freepascal.org/bugs.html), since if  
you ran into this it's quite possible that other people will do so as  
well.


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

Re: Problem with FPC2.0.2 and windows

Hans Mårtensson-2
Jonas Maebe wrote:

> They should be.
>
>> Thank you for your careful answer. I will return later if I am able  
>> to make a simple sample program that can reproduce the problem.
>> (Or may be I should stick to 1.0.10 that worked for me)
>
>
> It would be nice if you could provide the sample program (and submit  
> it as a bugreport at http://www.freepascal.org/bugs.html), since if  
> you ran into this it's quite possible that other people will do so as  
> well.


When trying to locate the problem I found out that the first problem was
due to my mistake, I'm sorry. The error message was

Error: Incompatible types: got "<address of function(LongWord, LongWord,
LongWord, LongInt):LongInt;StdCall>" expected "<procedure variable type
of function(LongWord, LongWord, LongInt, LongInt):LongInt;StdCall>"

I interpreted this as if the error was caused by an address in stead of
a procedure variable, but actually correcting the type of the 3rd
parameter was sufficient to remove the error.
FPC 1.0.10 compiled the statement with a longword in stead of a longint
correctly without any comments, but it looks like 2.0.2 has a much
stronger type checking.

But my second problem persists. The program is compiled, but the
dialogue box does not show up, when using 2.0.2.
Before I go on trying to locate this problem I must take into account
that Windows requires the data structure for dialogue boxes to be
aligned in a certain way, so I would like to ask the question:

Does PPC 2.0.2 handle alignment of data the same way as former versions?
Will the statements (the conditions)
  if (dword(pBoxtemplate) and 1)=1 then pBoxtemplate:=nil;
  if (dword(pBoxtemplate) and 2)=2 then inc(pBoxtemplate);
be treated the same way, and is
  pointer(pBoxItem) - pointer(pBoxAllokate)
still equal to the distance between the pointers measured in bytes,
regardless of the type of pBoxItem?

Hans Mårtensson






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

Re: Problem with FPC2.0.2 and windows

Tomas Hajny
Hans Mĺrtensson wrote:
 .
 .
> Does PPC 2.0.2 handle alignment of data the same way as former versions?
 .
 .

Actually, I don't think so - I believe the default alignment might have
changed from 2 to 4 (at least this seems to be indicated by my simple
test). You can check this easily for pBoxtemplate^ (or anything else as
required) by calling:

WriteLn (SizeOf (pBoxtemplate^));

Furthermore, you can enforce required alignment using {$PACKRECORDS x}.

Tomas

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

Re: Problem with FPC2.0.2 and windows

Jonas Maebe-2
In reply to this post by Hans Mårtensson-2

On 04 Jan 2006, at 17:51, Hans Mårtensson wrote:

> Does PPC 2.0.2 handle alignment of data the same way as former  
> versions?

The statements below have nothing to do with alignment.

> Will the statements (the conditions)
>  if (dword(pBoxtemplate) and 1)=1 then pBoxtemplate:=nil;

I can only think of one way to interpret this.

>  if (dword(pBoxtemplate) and 2)=2 then inc(pBoxtemplate);

Somewhere in the past, inc(pBoxtemplate) would have increased  
pBoxtemplate with one. Nowadays, this increases pBoxtemplate with  
sizeof(pBoxtemplate^). I don't know when this change was done though,  
but I'm quite confident it was before 1.0. If this is the behaviour  
you need, it's ok.

> be treated the same way, and is
>  pointer(pBoxItem) - pointer(pBoxAllokate)
> still equal to the distance between the pointers measured in bytes,  
> regardless of the type of pBoxItem?

Yes.


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

Re: Problem with FPC2.0.2 and windows

Hans Mårtensson-2
Jonas Maebe wrote:

>
> On 04 Jan 2006, at 17:51, Hans Mårtensson wrote:
>
>> Does PPC 2.0.2 handle alignment of data the same way as former  
>> versions?
>
>
> The statements below have nothing to do with alignment.
>
>> Will the statements (the conditions)
>>  if (dword(pBoxtemplate) and 1)=1 then pBoxtemplate:=nil;
>
>
> I can only think of one way to interpret this.
>
>>  if (dword(pBoxtemplate) and 2)=2 then inc(pBoxtemplate);
>

The type of pBoxtemplate is ^word.
Is it not true that
  (dword(pBoxtemplate) and 1)=1
evaluates to TRUE, if and only if pBoxtemplate is NOT aligned to a word
boundary (16 bit boundary)?

And then, assuming pBoxtemplate is aligned to word boundary, is it not
true, that
  if (dword(pBoxtemplate) and 2)=2
evaluates to TRUE, if pBoxtemplate is NOT aligned to a dword boundary
(32 bit boudary), causing the statement
  if (dword(pBoxtemplate) and 2)=2 then inc(pBoxtemplate);
to make the pBoxtemplate align to a dword boundary (by eventually adding
2 to pBoxtemplate (because sizeof(word)=2)??

Hans Mårtensson

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

Re: Problem with FPC2.0.2 and windows

Jonas Maebe-2

On 04 Jan 2006, at 21:51, Hans Mårtensson wrote:

>>> Does PPC 2.0.2 handle alignment of data the same way as former  
>>> versions?
>>
>> The statements below have nothing to do with alignment.
>>
> The type of pBoxtemplate is ^word.
> Is it not true that
>  (dword(pBoxtemplate) and 1)=1
> evaluates to TRUE, if and only if pBoxtemplate is NOT aligned to a  
> word boundary (16 bit boundary)?
>
> And then, assuming pBoxtemplate is aligned to word boundary, is it  
> not true, that
>  if (dword(pBoxtemplate) and 2)=2
> evaluates to TRUE, if pBoxtemplate is NOT aligned to a dword  
> boundary (32 bit boudary), causing the statement
>  if (dword(pBoxtemplate) and 2)=2 then inc(pBoxtemplate);
> to make the pBoxtemplate align to a dword boundary (by eventually  
> adding 2 to pBoxtemplate (because sizeof(word)=2)??

Yes, but this is independent of how the compiler handles alignment of  
data.


Jonas

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

Re: Problem with FPC2.0.2 and windows

Hans Mårtensson-2
Jonas Maebe wrote:

>
> On 04 Jan 2006, at 21:51, Hans Mårtensson wrote:
> The type of pBoxtemplate is ^word.
>
>> Is it not true that
>>  (dword(pBoxtemplate) and 1)=1
>> evaluates to TRUE, if and only if pBoxtemplate is NOT aligned to a  
>> word boundary (16 bit boundary)?
>>
>> And then, assuming pBoxtemplate is aligned to word boundary, is it  
>> not true, that
>>  if (dword(pBoxtemplate) and 2)=2
>> evaluates to TRUE, if pBoxtemplate is NOT aligned to a dword  
>> boundary (32 bit boudary), causing the statement
>>  if (dword(pBoxtemplate) and 2)=2 then inc(pBoxtemplate);
>> to make the pBoxtemplate align to a dword boundary (by eventually  
>> adding 2 to pBoxtemplate (because sizeof(word)=2)??
>
>
> Yes, but this is independent of how the compiler handles alignment of  
> data.
>
OK, then I really don't understand where the problem is.

It seems difficult to me to supply a bug report, because it is still so
uncertain where the problem lies.
But I attach the source code to my test program, in case you can do
anything with it.

When I compile this source code with FPC 1.0.10, it produces a program
that makes a window with one menu item. When you click on it, a dialogue
box pops up.

But when I compile the same source code with FPC 2.0.2, I still get a
program that makes the window. But the dialogue box does not show, when
you click the menu item.

Hans Mårtensson


Program test;
// Program for testing dialogue boxes

{$APPTYPE GUI}

Uses windows;

Const
  AppName = 'Lydexperiment';

var
  AMessage: Msg; hWindow: HWnd;
  pbox2: pointer; box2var1, box2var2: longint;

  Boxtemplate: DlgTemplate;
  Boxtemplatesize: word;
  pBoxAllokate: ^word; //Start of allocated memory
  pBoxtemplate: ^word; //Start of Boxtemplate
  pBoxItem: ^word;     //Start of free space after added items

{$Rangechecks off}
//**************************************************************
Procedure newboxtemplate(title: string; width, height, boxsize: word);
var i:integer;
begin boxtemplatesize:=boxsize; pBoxItem:=nil;
  getmem(pBoxAllokate,boxsize); pBoxtemplate:=pBoxAllokate;
  if (dword(pBoxtemplate) and 1)=1 then pBoxtemplate:=nil;
  if (dword(pBoxtemplate) and 2)=2 then inc(pBoxtemplate);
  if pBoxtemplate=nil then exit;
  Boxtemplate.style:=DS_CENTER or WS_POPUP or WS_CAPTION or WS_SYSMENU or DS_MODALFRAME;
  Boxtemplate.dwextendedstyle:=0;
  Boxtemplate.x:=0; Boxtemplate.y:=0; Boxtemplate.cx:=width; Boxtemplate.cy:=height;
  Boxtemplate.cdit:=0; pBoxItem:=pointer(pBoxtemplate) + sizeof(Boxtemplate);
  pBoxItem^:=0; inc(pBoxItem); pBoxItem^:=0; inc(pBoxItem); // menu and class
  for i:=1 to length(title) do begin pBoxItem^:=ord(title[i]); inc(pBoxItem) end;
  pBoxItem^:=0; inc(pBoxItem) end; // terminating 0 in titel

Procedure newboxtemplate(title: string; width, height: word);
begin newboxtemplate(title, width, height, 2000) end;

//**************************************************************
Procedure appendboxitem(id: word; style: DWORD; class: word; title: string; x,y,width,height: WORD);
var i: word; Bi: Dlgitemtemplate;
begin if pBoxItem=nil then exit; if (dword(pBoxItem) and 2)=2 then inc(pBoxItem);
  Bi.style:=style or WS_VISIBLE or WS_CHILD;
  if class<>$82 then Bi.style:=BI.style or WS_TABSTOP;
  Bi.dwextendedstyle:=0;
  Bi.x:=x; Bi.y:=y; Bi.cx:=width; Bi.cy:=height;  Bi.id:=id;
  move(Bi,pBoxItem^,sizeof(Bi)); inc(pBoxItem,sizeof(bi) div 2);
  pBoxItem^:=$FFFF; inc(pBoxItem);  pBoxItem^:=class; inc(pBoxItem); //standard-class presumed
  for i:=1 to length(title) do begin pBoxItem^:=ord(title[i]); inc(pBoxItem) end;
  pBoxItem^:=0; inc(pBoxItem); // terminating 0 in titel
  pBoxItem^:=0; inc(pBoxItem); // creation data is not used
  inc(Boxtemplate.cdit); move(Boxtemplate,pBoxtemplate^,sizeof(Boxtemplate));
  end;

Function getboxtemplate: pointer;
var nbox: DWORD; pBoxny: ^word;
begin if pBoxItem=nil then begin
    getboxtemplate:=nil; MessageBox (0,'WinCreate failed','Error',MB_OK); exit end
  else getboxtemplate:=pBoxtemplate;
  nbox := pointer(pBoxItem) - pointer(pBoxAllokate); getmem(pBoxny,nbox+2);
  if pBoxny=nil then exit;
  if (dword(pBoxny) and 1)=1 then pBoxny:=nil;
  if (dword(pBoxny) and 2)=2 then begin inc(pBoxny); dec(nbox,2) end;
  move(pBoxtemplate^,pBoxny^,nbox); freemem(pBoxAllokate,Boxtemplatesize);
  pBoxtemplate:=pBoxny; getboxtemplate:=pBoxny; pBoxItem:=nil end;

//**************************************************************
//End of dialogue box data structure making procedures

//Start of specific dialogue box definition
//******************************************************************************
Function Box2Proc(Box: hWnd; Message: UINT; WPrm : longint; LPrm: longint): Longint; stdcall;
begin Box2Proc:=1; if LPrm=0 then ;
  case Message of
    WM_INITDIALOG: begin box2var1:=8000; box2var2:=2;
      case box2var1 of
        8000: Checkradiobutton(Box,2,7,2);
        11025: Checkradiobutton(Box,2,7,3);
        16000: Checkradiobutton(Box,2,7,4);
        22050: Checkradiobutton(Box,2,7,5);
        48000: Checkradiobutton(Box,2,7,6);
        44100: Checkradiobutton(Box,2,7,7);
        end;
      if box2var2>1 then CheckDlgButton(Box,8,BST_CHECKED)
      else CheckDlgButton(Box,8,BST_UNCHECKED);
      setfocus(longint(Box)); Box2Proc:=0 end;
    WM_COMMAND: case LOWORD(WPrm) of
      2: begin Checkradiobutton(Box,2,7,2); box2var1:=8000 end;
      3: begin Checkradiobutton(Box,2,7,3); box2var1:=11025 end;
      4: begin Checkradiobutton(Box,2,7,4); box2var1:=16000 end;
      5: begin Checkradiobutton(Box,2,7,5); box2var1:=22050 end;
      6: begin Checkradiobutton(Box,2,7,6); box2var1:=48000 end;
      7: begin Checkradiobutton(Box,2,7,7); box2var1:=44100 end;
      8: if box2var2>1 then begin box2var2:=1; CheckDlgButton(Box,8,BST_UNCHECKED) end
        else begin box2var2:=2; CheckDlgButton(Box,8,BST_CHECKED) end;
      9: begin enddialog(Box,1) end end;
    WM_CLOSE: enddialog(Box,0);
    else Box2Proc:=0 end end;

Procedure showbox(window: hWnd);
begin if DialogBoxIndirect(system.MainInstance,pBox2, Window, @Box2Proc)=0 then exit end;

//******************************************************************************

Procedure setboxtemplates;
begin
  newboxtemplate('Lydkvalitet',87,90);
  appendboxitem(1,SS_SIMPLE,$82,'Samplerate (s. pr. sek.)',5,5,80,12);
  appendboxitem(2,BS_AUTORADIOBUTTON,$80,'8000',5,20,40,12);
  appendboxitem(3,BS_AUTORADIOBUTTON,$80,'11025',50,20,40,12);
  appendboxitem(4,BS_AUTORADIOBUTTON,$80,'16000',5,35,40,12);
  appendboxitem(5,BS_AUTORADIOBUTTON,$80,'22050',50,35,40,12);
  appendboxitem(6,BS_AUTORADIOBUTTON,$80,'48000',5,50,40,12);
  appendboxitem(7,BS_AUTORADIOBUTTON,$80,'44100',50,50,40,12);
  appendboxitem(8,BS_CHECKBOX,$80,'Stereo',6,68,40,12);
  appendboxitem(9,BS_DEFPUSHBUTTON,$80,'OK',50,70,30,12);
  pBox2:=getboxtemplate;  
  end;

//*****************************************************************************
//End of specific dialogue box definition

//The rest of the program is for making a window
//*****************************************************************************

Function WindowProc(Window: hWnd; AMessage: UINT; WPrm: WParam; LPrm: LParam): LResult; stdcall; export;
Var nrmenu: longint; //ps: paintstruct; dc: hdc; r: rect;
begin WindowProc := 0;
  Case AMessage of
//    wm_Paint: begin
//      dc:=BeginPaint(Window,@ps);
//      EndPaint(Window,ps);
//      Exit;
//      end;
    wm_Close: ; //Lad DefWindowProc take care of close
    wm_Destroy: begin PostQuitMessage(0); exit end;
    wm_char: ;
    wm_Command: begin
      NrMenu := WPrm and $FFFF;
      Case NrMenu Of
        100: showbox(window);
        End; End; End;
  WindowProc := DefWindowProc(Window,AMessage,WPrm,LPrm); End;

//**************************************************************
Function WinRegister: Boolean;
var  WindowClass: WndClass;
Begin With WindowClass Do Begin
    Style := cs_hRedraw Or cs_vRedraw;
    lpfnWndProc := WndProc(@WindowProc);
    cbClsExtra := 0;
    cbWndExtra := 0;
    hInstance := system.MainInstance;
    hIcon := LoadIcon(0,idi_Application);
    hCursor := LoadCursor(0,idc_Arrow);
    hbrBackground := GetStockObject(LTGRAY_BRUSH);
    lpszMenuName := '';
    lpszClassName := AppName;
    End;
  WinRegister := RegisterClass(WindowClass)<>0;
  If not WinRegister then begin MessageBox(0,'Register failed',Nil, mb_Ok); exit end;
  end;

//**************************************************************
Function WinCreate: hWnd;
Var hWindow: hWnd;
    Menu: hMenu;
Begin
  hWindow := CreateWindow(AppName,AppName,ws_OverlappedWindow,
  cw_UseDefault,cw_UseDefault,cw_UseDefault,cw_UseDefault,0,0,system.MainInstance,Nil);
  If hWindow<>0 then begin
    Menu := CreateMenu;
    AppendMenu(Menu,MF_STRING,100,'&Show dialogbox for test');
    SetMenu(hWindow,Menu);
    ShowWindow(hWindow,CmdShow);
    ShowWindow(hWindow,SW_SHOW);
    UpdateWindow(hWindow);
    end;
  Wincreate := hWindow
  end;


//*************** Main program **********************************
Begin
  If not WinRegister then exit;
  hWindow := WinCreate;
  If longint(hWindow)=0 then begin MessageBox (0,'WinCreate failed',Nil,MB_OK); exit end;
  setboxtemplates;
  While GetMessage(@AMessage,0,0,0) do
  begin TranslateMessage(AMessage); DispatchMessage(AMessage) end;
  Halt(AMessage.wParam) End.

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

Re: Problem with FPC2.0.2 and windows

Jonas Maebe-2

On 04 Jan 2006, at 23:46, Hans Mårtensson wrote:

> When I compile this source code with FPC 1.0.10, it produces a  
> program that makes a window with one menu item. When you click on  
> it, a dialogue box pops up.
>
> But when I compile the same source code with FPC 2.0.2, I still get  
> a program that makes the window. But the dialogue box does not  
> show, when you click the menu item.

I hope someone else can take it over from here, because I don't have  
Windows (or even a computer which can run Windows).


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

Re: Problem with FPC2.0.2 and windows

Hans Mårtensson-2
Jonas Maebe wrote:

>
> On 04 Jan 2006, at 23:46, Hans Mårtensson wrote:
>
>> When I compile this source code with FPC 1.0.10, it produces a  
>> program that makes a window with one menu item. When you click on  
>> it, a dialogue box pops up.
>>
>> But when I compile the same source code with FPC 2.0.2, I still get  
>> a program that makes the window. But the dialogue box does not  show,
>> when you click the menu item.
>
>
> I hope someone else can take it over from here, because I don't have  
> Windows (or even a computer which can run Windows).



OK, thank you for your help so far.
I will try to do further experiments in order to locate the problem.
I think it must be in the data structure that defines the dialog box,
which the two compiler versions generate differently.

I appreciate very much the work done by the people behind FPC.
Not only because it is free and advanced, but also because Pascal is
nicer than any other programming language I have seen, in my opinion

Hans Mårtensson

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

Re: Problem with FPC2.0.2 and windows

Jonas Maebe-2

On 06 Jan 2006, at 15:37, Hans Mårtensson wrote:

> OK, thank you for your help so far.
> I will try to do further experiments in order to locate the problem.
> I think it must be in the data structure that defines the dialog  
> box, which the two compiler versions generate differently.

You can try writing the size of the structure using sizeof(), and the  
individual offset using things like "pointer(@recordvar.field) -  
pointer(@recordvar)", and then compare the values between the 1.0.10  
and 2.0.2 version.

> I appreciate very much the work done by the people behind FPC.
> Not only because it is free and advanced, but also because Pascal  
> is nicer than any other programming language I have seen, in my  
> opinion

Thanks!


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

Re: Problem with FPC2.0.2 and windows

Martin Schreiber
In reply to this post by Jonas Maebe-2
On Friday 06 January 2006 12.32, Jonas Maebe wrote:
> I hope someone else can take it over from here, because I don't have
> Windows (or even a computer which can run Windows).

The problem is in rtl/win32/wininc/struct.inc, the smallint's were integer's:

    DLGTEMPLATE = packed record //from rtl/win32/wininc/struct.inc
          style : DWORD;
          dwExtendedStyle : DWORD;
          cdit : WORD;
          x : smallint; //integer;
          y : smallint; //integer;
          cx : smallint; //integer;
          cy : smallint; //integer;
       end;

     pdlgtemplate = ^dlgtemplate;
     DLGITEMTEMPLATE = packed record
          style : DWORD;
          dwExtendedStyle : DWORD;
          x : smallint; //integer;
          y : smallint; //integer;
          cx : smallint; //integer;
          cy : smallint; //integer;
          id : WORD;
       end;

Who makes the bug report?

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

Re: Problem with FPC2.0.2 and windows

Jonas Maebe-2

On 06 Jan 2006, at 19:12, Martin Schreiber wrote:

>> I hope someone else can take it over from here, because I don't have
>> Windows (or even a computer which can run Windows).
>
> The problem is in rtl/win32/wininc/struct.inc, the smallint's were  
> integer's:

Thanks, I've committed your changes. If someone can verifies it works  
in 2.1.1 tomorrow, I'll merge it back to 2.0.3 as well.


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

Re: Problem with FPC2.0.2 and windows

Hans Mårtensson-2
Jonas Maebe wrote:

>
> On 06 Jan 2006, at 19:12, Martin Schreiber wrote:
>
>> The problem is in rtl/win32/wininc/struct.inc, the smallint's were  
>> integer's:
>
>
> Thanks, I've committed your changes. If someone can verifies it works  
> in 2.1.1 tomorrow, I'll merge it back to 2.0.3 as well.
>

I have downloaded the 2.1.1 snapshot and compiled my testprogram with
it, and the problem is still there: no dialog box showes up.

Then, by help of the windows function GetLastError, I have found out
that windows in my program after call to
  DialogBoxIndirect(0,pBox2, Window, @Box2Proc)
returns LastError 1812, meaning "resource not found".

That made me think about the first two parameters.
The first one should be a handle to an instance of the module. Here I
use 0, believing that this makes windows use the current module.
I'm not sure about this, but it worked in the program compiled with FPC
1.0.10, and windows hasn't changed.

Next the pBox2 should point to the data structure, defining the dialog
box. The data should be in global memory.
I have constructed the data by help of some pointers of type ^word,
pointing to something, allocated by getmem, using move to put data
there, then finally assigned the pBox2 that is of type pointer.
(typeless I mean).
I can't see if that possibly can be treated diffently in the 2.0.2 compiler?

Hans Mårtensson

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

Re: Problem with FPC2.0.2 and windows

Jonas Maebe-2

On 07 Jan 2006, at 18:43, Hans Mårtensson wrote:

> I have downloaded the 2.1.1 snapshot and compiled my testprogram  
> with it, and the problem is still there: no dialog box showes up.

Can you check the date of the compiler with "fpc -iD"? As far as I  
know no new snapshot was built last night because of errors compiling  
the graph unit.


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

Re: Problem with FPC2.0.2 and windows

Martin Schreiber
In reply to this post by Hans Mårtensson-2
On Saturday 07 January 2006 18.43, Hans Mårtensson wrote:
> I have downloaded the 2.1.1 snapshot and compiled my testprogram with
> it, and the problem is still there: no dialog box showes up.
>

Your testcase worked for me with FPC 2.0.2 and the modified DLGTEMPLATE and
DLGITEMTEMPLATE.

> Then, by help of the windows function GetLastError, I have found out
> that windows in my program after call to
>   DialogBoxIndirect(0,pBox2, Window, @Box2Proc)
> returns LastError 1812, meaning "resource not found".

This is the same error as you get with FPC 2.0.2 and the unmodified records.

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

Re: Problem with FPC2.0.2 and windows

Hans Mårtensson-2
In reply to this post by Jonas Maebe-2
Jonas Maebe wrote:

>
> Can you check the date of the compiler with "fpc -iD"? As far as I  
> know no new snapshot was built last night because of errors compiling  
> the graph unit.


Right. Even though the zip file date is more recent, the "fpc -D" returns:
2005/12/29

Hans Mårtensson

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

Re: Problem with FPC2.0.2 and windows

Hans Mårtensson-2
In reply to this post by Martin Schreiber
Martin Schreiber wrote:

>Your testcase worked for me with FPC 2.0.2 and the modified DLGTEMPLATE and
>DLGITEMTEMPLATE.
>  
>

Yes, I'm convinced that the problem lies where you have pointed it out.
I have let my test program show sizeof(DLGTEMPLATE) and the output from
the version compiled with 2.0.2 was
  sizeof(DLGTEMPLATE)=26
while the old working version had
  sizeof(DLGTEMPLATE)=18
which fits to 4 longint in stead of 4 shortint.

Now, I'm not familiar with the development of the PFC,
where and when can I download the corrected version of 2.0.2?

Hans Mårtensson

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
12