Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 5 Jahren
Letzter Beitrag:
vor 4 Jahren, 11 Monaten
Beteiligte Autoren:
Tor-Bjarne, Alexandre Leclerc, Danny Lauwers

Instrict vars

Startbeitrag von Tor-Bjarne am 16.08.2013 10:45


Is it possible to use variablenames as names for a definition of a class or structure somhow?

the small code snip below show what I want to do:

fld is string =EnumControl(iFormName, nControlCounter)

myCtrl is Structure // -OR- object
name is string
Xpos is int

fld = "Obj_"+fld
{fld} is dynamic myCtrl = new myctrl
{fld}.name = "Something"
{fld}.Xpos = 10

Or is there another way of building dynamic structures like the one over? - MemZone seems only to let me define 1 keyfield and 1 datafield I need several.




Hi Tor-Bjarne,

The nearest I can think of is a composite variable. But this type is usually used only when the variable "type/format" will not be used anywhere else in the application. http://doc.pcsoft.fr/en-US/?1514061

If the "type/format" of the variable must be used somewhere else (another proc, etc.), you must declare a structure (or a class) so that they can know the structure of the variable.

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 16.08.2013 12:12

Thank you for your reply Alexandre

I want a class to be able to store temporal data like a array structure or a record/table, usually I define a file in the analyze create a view from this and problem is solved.

But for my Windows resize class I wanted the class to be in the SCM without a requierd analyze attached since the plan is to use this shared class in several projects.

After som study I found a workaround that I`d like to share, for some of you I guess this is "beginner stuff" but perhaps somebody find parts of it usefull as this can be adopted to other solutions/classes.


I need a resize class that changes fontsize width and heigt on controls, so a window (perhaps without maximize activated) looks the
same in different screen resolutions, I`m not trying to re-write the excellent ancor resizing scheme in WinDev. Just a different approach.

As a example I show you 2 screens, the first original is my old invoice app written when most people had 1024 x 768 resolution and my windowssize at that time.
Example screen 1

The second screen shows my app with a screen resolution more common nowdays 1920 x 1020 - the app is the same just have an resize attached to it.
Example screen 2

So I need to to do some calculation, move controls and change fontsize and so forth.
I also need to store InitialX,Y in a memory table/Queue without any analyze :)

In my class I have something like this to simulate a memory table/queue:

ScreenObject is a Class
dsCtrlObj is Data Source
View_is_defined is boolean

In my Init method I got:

IF :View_is_defined = True THEN

AFile is File Description
AnItem is Item Description

AFile..Name = "TempFile"
AFile..DescribedDirectory = fTempPath()
AFile..Type = hFileView

// Describing the "Ctrl name" item
AnItem..Name = "Name"
AnItem..Type = hItemText
AnItem..Size = 40
AnItem..KeyType = hUniqueKey
HDescribeItem(AFile, AnItem)

// initial height width x,y pos
AnItem..Name = "InitialWidth"
AnItem..Type = hItemReal4
HDescribeItem(AFile, AnItem)

AnItem..Name = "InitialHeight"
AnItem..Type = hItemReal4
HDescribeItem(AFile, AnItem)

AnItem..Name = "initialX"
AnItem..Type = hItemReal4
HDescribeItem(AFile, AnItem)

AnItem..Name = "initialY"
AnItem..Type = hItemReal4
HDescribeItem(AFile, AnItem)

AnItem..Name = "New_Width"
AnItem..Type = hItemReal4
HDescribeItem(AFile, AnItem)

AnItem..Name = "New_Height"
AnItem..Type = hItemReal4
HDescribeItem(AFile, AnItem)

AnItem..Name = "New_X"
AnItem..Type = hItemReal4
HDescribeItem(AFile, AnItem)

AnItem..Name = "New_Y"
AnItem..Type = hItemReal4
HDescribeItem(AFile, AnItem)

// Validates the description of the data file

:View_is_defined = True

Now I have a view/memory table in my Class with a record structure and I dont have to mess with memoryzones, arrays or queues :-)
And I can use the"for each", "Hreadseek" h-commands.


von Tor-Bjarne - am 18.08.2013 12:04
Hi Tor-Bjarne,

You certainly have a reason for this, but I ask the question since I did not think of one: Why are you not simply using a structured array?

This would would be much faster and easier to handle all this data. You can also use "for each" and Search functions.

STIniInfo is Structure
Name is string
InitialWidth is int
InitialHeight is int
initialX is int
initialY is int
New_Width is int
New_Height is int
New_X is int
New_Y is int

ScreenObject is Class
m_tabInfo is array of STIniInfo

// ...

// Easily add an object:
let n = Add(m_tabInfo)
m_tabInfo[n].Name = "Control1"
m_tabInfo[n].InitialWidth = 50
m_tabInfo[n].InitialHeight = 50
m_tabInfo[n].initialX = 10
m_tabInfo[n].initialY = 10
// Use Sort() if desired to optimize search on name later... many options are available...

// Unoptimized example of default search:
let i = Seek(m_tabInfo,asLinear+tccIgnoreCase,"Name;initialX","Control1",10)
m_tabInfo.New_Width = 12
// ...

// Example of loop:
FOR EACH stInfo OF m_tabInfo
IF stInfo.Name > "C" THEN
stInfo.New_X = stInfo.initialX*1.2

This approach would be much more optimized for what you want to achieve. But maybe you have good reasons why this would not be best for you. (It might be a design reason.) But using the HF core for that kind if job is not the best. (Also, since WinDev 18 the JIT compiler is optimized for OOP and structures.)

Kind regards,
Alexandre Leclerc

von Alexandre Leclerc - am 19.08.2013 12:59
Hi Alexandre,

I`m not sure how much the speed penalty is, since the view is in memory (some, I agree, but noticable?) and I do not have a zillion of controls in my screens.

But to be quite honest (since I`m relative new to windev) I did not see this solution.

If you read my first post again, this is "somehow" what I asked for thinking I had to use instrict variables. Perhaps a bad explanation from me.

I was trying to make a class holding a structure and wanted to define the class several times making a list of objects the way you now have shown me :)

Another reason why I tend to use Views is that in practical use they are as a hyperfile and responds to the same H-Commands and there are a lot of them lying around to manipulate my data.

Anyway, the class is half way written and if speed drops when testing against more real projects (only testet one so far), I will re-write it using your excelent solution.

My Class is a "Zoom function" for a window taking into account the ancor/screen resolution as shown in examples below:

Example 1: Original screen and size
Example 2: Witout class and several containers with ancor width and hight, no splitters
Example 3: Example 2, width class activated
Example 4: Window maximized width class activated



von Tor-Bjarne - am 20.08.2013 13:35
Hi Tor-Bjarne,

I've read you first post again and indeed I did not understood clearly what you were trying to do. I'm sorry for that. The good thing is that your solution is going forward.

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 20.08.2013 15:39

Yes, Alexandre, I was a bit unclear :) - Anyway I`m in the proccess of rewriting my class using your technique!

And if I forgot to mention it earlier, thank you wery much.


von Tor-Bjarne - am 20.08.2013 18:02

Just asking if the class and the technique you use have let to a good solution to dynamically scale your application to "any" resolution.

Do you call this for every window when resized, or could this be something thats done on project level ? Resize the active and open windows when the resize event is captured on project/global level. This way any application could be made scalable with a few added lines of code in the project??

Pcsoft: maybe make this a setting on the window please !


von Danny Lauwers - am 01.09.2013 21:56
Hi Danny,

Yes - I think this is a good solution, the window looks the same only zoomed up, on a bigger screen resolution than the project was developed for.
This way (in other languages) I extend the life span of a product.

If you see the examples, you vil notice I can make a 1024 x 768 app and it will appear equal on all screen-resolutions.

In every window I would like to resize I have 2 calls to the resize class:

in window initcode I have

wr.ini() // reads all the controls and their initial position, fontsize etc.

In the resize event of the window I have a call to wr.resize.

The problem/challange is that with the WinDev Edit control`s caption, seems there`s no property to change the fontsize etc.
(Or I have not found it)

I Will see if I can set the caption to "", and overlay a cloned static.

Next steps is:

1. to make a tweaker that can change the background and forgrund color of all controlls run-time (If you use our system on a portable PC outside in the sun (Our Africa project for Zambia) Customer will ned fields with black background and white fontcolor - then normal once inside again.)

2. Since we have a list of all controls, we can make a "GUI Editor" - some systems require customers to be able to move fields around the screen, hiding or disabling fields that is not requierd (at that particular site)

@Alexandre - List of arrays or View (using H-commands) - tested both no real time difference, compared to time used in WinDev on moving, resizing , and change fonts on controls.

PS: I would love a "template" that could inject code in the "all Windows.init" and "all windows.resize" :)


von Tor-Bjarne - am 02.09.2013 11:47
Hi Tor-Bjarne,

The problem/challange is that with the WinDev Edit control`s caption, seems there`s no property to change the fontsize etc.
(Or I have not found it)

A simple turn-arround to this limitation is to do the following:

EDT_Test..Caption = gFontSize(20)+gToText(EDT_Test..Caption)

It will be easier to implement that way.

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 03.09.2013 12:26
Hi Alexandre,

Thank you!! - This works as a charm :)

Do you have a way (via code) to change the caption`s width ? - When I make the EDIT field wider the caption area`s width stays the same width, as oposite to the "input area" that get wider.


von Tor-Bjarne - am 03.09.2013 20:03
Hi Tor-Bjarne,

You got me on that one. I think this is not possible in WD18. This looks like a good suggestion to send to the Free Technical Support.

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 03.09.2013 20:51
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.