Diferent forms, diferent results.

Started by Elias Montoya, October 17, 2006, 04:28:27 AM

Previous topic - Next topic

Elias Montoya

Paul, sorry to require your help again but i have been struggling with
this for several hours now and i cant get it to work.

I have been having wierd results depending on the form i put the code in.

Here is the situation, I have a main form with a button named "Facturar"
wich points to form #11, named "Factura" in this form, i have this code
to be executed in WM_CREATE:

'------------------------------------------------------------------------------------------------------------------------
Function Factura_WM_CREATE ( _
                           hWndForm As Dword, _  ' handle of Form
                           ByVal UserData As Long _  'optional user defined Long value
                           ) As Long


Local FF As Long
Local Hmem As Dword
Local FormAsText As String
                           
FF = FreeFile
Open (ProgDir & "DTB\Formas\Factura.CGF") For Binary Access Read As #FF
FormAsText = Space$(Lof(FF))
Get #FF,,FormAsText
Close #FF
Hmem = GlobalAlloc(%GMEM_FIXED Or %GMEM_ZEROINIT, Len(FormAsText))
MsgBox Str$(GlobalSize(hMem))
If Hmem Then
 Poke$ Hmem, FormAsText
 SendMessage(HWND_FACTURA_EGRID321, %EG_SETDATASTREAM, HMem, %EG_APPLYPROPERTIES Or %EG_RESTORESELECTION Or %EG_RESTOREPOSITION)
 SendMessage(HWND_FACTURA_EGRID321, %EG_CLEANFORMULAS, 0, 0)  
 GlobalFree(HMem)
 HMem = 0
End If

.
.
.
.
End function


That loads a form in an Egrid32, it loads correctly every time. Even in
the debugger.

The thing is that i have another button in the main form that points to
Form #12, named "DocumentVisor", and in that form i have this code
to get executed under WM_CREATE:

Function DOCUMENTVISOR_WM_CREATE ( _
                           hWndForm As Dword, _  ' handle of Form
                           ByVal UserData As Long _  'optional user defined Long value
                           ) As Long


Local FF As Long
Local Hmem As Dword
Local FormAsText As String
                           
FF = FreeFile
Open (ProgDir & "DTB\Formas\Factura.CGF") For Binary Access Read As #FF
FormAsText = Space$(Lof(FF))
Get #FF,,FormAsText
Close #FF
Hmem = GlobalAlloc(%GMEM_FIXED Or %GMEM_ZEROINIT, Len(FormAsText))
MsgBox Str$(GlobalSize(hMem))
If Hmem Then
 Poke$ Hmem, FormAsText
 SendMessage(HWND_DOCUMENTVISOR_EGRID321, %EG_SETDATASTREAM, HMem, %EG_APPLYPROPERTIES Or %EG_RESTORESELECTION Or %EG_RESTOREPOSITION)
 SendMessage(HWND_DOCUMENTVISOR_EGRID321, %EG_CLEANFORMULAS, 0, 0)  
 GlobalFree(HMem)
 HMem = 0
End If

.
.
.
.
.
.
.
End Function



The code snippets i added here contains code that is not relevant, i replaced that code with Dots. problem occurs also if i remove that code.

The thing is that the program crashes there. Same code, same procedure
to be called, the only diferent thing is the form. It crashes every time and
PB debugger complains about program trying to read or write to an invalid memory address.

Do you have any idea why this is happening?

Ill try to send you a sample reproducing this behaviour.

Elias Montoya

Now i cant remove a form that contains controls that shows System
fonts... it reuses to be removed!! :( i cant go any further.

Elias Montoya

Now it started giving me all sorts of errors out of my power to fix.
duplicate handle names, and resource file not being able to be created.

It all started by re-using an existing form. If the form already exists in
the project it creates a mess... I wanted to add an existing form and
modify it as necesiary. But modifying one changes the other.

I think ill restart this tomorrow.

Zzzzzz

TechSupport

Quote from: Elias MontoyaIt all started by re-using an existing form. If the form already exists in the project it creates a mess... I wanted to add an existing form and modify it as necesiary. But modifying one changes the other.

Using a copy of an existing form can cause a problem if you don't follow these directions:

"Use Windows' File Explorer and make a copy of your Form's .frm and corresponding .frx file. Rename these disk files to whatever you wish. You should now be able to add the new Form to your project via the Project, Add Form, Existing menu option.

You must change the new Form's Name property because an existing file in your project will already have that name. You will also have to search/replace in the code for any references in the Form that uses the old name."

Elias Montoya

Logic told me i had to do that, and i did it the first time.

Doing that works fine paul, but causes memory corruption that builds
up until it explodes in a crash, it usually takes several executions to crash.
PB debugger detects it in the first execution though.

That was the first problem and everything else (double declarations, PBR problem and other problems) happened after i re-used the same form
without changing the name.

Lucky me i had a back up, i am now fresh, i will (later because i have to
delivery this App on time) create a sample program and send it to you so
you can see this strange behaviour.

Elias Montoya

Withdrawn. I thought problem was gone, but comes and goes. :(
Debugger says something about Heap...

Elias Montoya

Hello Paul, I uninstalled a game i had in my computer, and after that, the
problem is gone, i am not having more problems and the debugger doesnt
complain about anything anymore! :)

Jean-Pierre LEROY

Hello Elias,

Just curious :

 how do you know that the debugger complain or not with a FireFly project ?
 How do you test your project with the debugger ?


Thank you.
Jean-Pierre

TechSupport

Also curious as to whether the code you are using to load a FireFly Form into a grid (?) may be corrupting memory.

FF = FreeFile
Open (ProgDir & "DTB\Formas\Factura.CGF") For Binary Access Read As #FF
FormAsText = Space$(Lof(FF))
Get #FF,,FormAsText
Close #FF
Hmem = GlobalAlloc(%GMEM_FIXED Or %GMEM_ZEROINIT, Len(FormAsText))
MsgBox Str$(GlobalSize(hMem))
If Hmem Then
 Poke$ Hmem, FormAsText
 SendMessage(HWND_DOCUMENTVISOR_EGRID321, %EG_SETDATASTREAM, HMem, %EG_APPLYPROPERTIES Or %EG_RESTORESELECTION Or %EG_RESTOREPOSITION)
 SendMessage(HWND_DOCUMENTVISOR_EGRID321, %EG_CLEANFORMULAS, 0, 0)    
 GlobalFree(HMem)
 HMem = 0
End If

Elias Montoya

Quote from: Jean-Pierre LEROYHello Elias,
Just curious :
 how do you know that the debugger complain or not with a FireFly project ?
 How do you test your project with the debugger ?

Thank you.
Jean-Pierre

I open Explorer and browse to my Project folder, then i open the MAIN
file of the generated code, in my case it is called: CODEGEN_ALAMONEON_MAIN.bas

Then i open it in PB editor, and click "Compile and Debug current file".
Thats all.

Paul,
No, im not using a firefly form in Egrid32 (Although i could!! :)), i am
using Egrid32 form designer in my app to design Contracts and Invoices
in my database, like a template that can be used for printing the
documents.

The designer saves the Egrid32 form, wich i use as template. In this case
the invoice template that the form designer saves is called "Factura.CGF".

:)

Elias Montoya

Just to add couple thoughts...

WOW paul. Firefly is amazing, it allowed me to do something
that even knowing firefly, i didnt know i could!!

Certaily great!! i am even thinking that you (or even me!!)
could create some Video Tutorials (like the ones for flash
in LearnFlash.Com)!!!

I will create Some tutorial Videos for how to use Egrid32 in
Firefly One of these days! I plan to make a video showing
how to embed the form designer in a Firefly appication and
allow User to design their own documents...

Firefly + Egrid32 is a really powerful Combination!!!!!!

:D