PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → How to create a class based on a variable name?
How to create a class based on a variable name?
Iniciado por jflietstra, 02,abr. 2005 11:46 - 7 respuestas
Publicado el 02,abril 2005 - 11:46
Hello,
How can i create a class based on a name in a variable?
The "lClassName is class" gives a error
i have also tried "{lClassName} is class"
Here is some code
lListFile is string
lListFile = HListFile(hLstNormal)
lStringCount is int = StringCount(lListFile,RC)
lFileNumber is int
lFileName is string
lClassName is string
FOR lFileNumber = 1 TO lStringCount
lFileName = ExtractString(lListFile,lFileNumber,RC)
lClassName = "FM_"+lFileName
lClassName is class
Inherit from FileManager
END
END
Publicado el 02,abril 2005 - 15:09
Hello,
How can i create a class based on a name in a variable?
The "lClassName is class" gives a error
i have also tried "{lClassName} is class"
Here is some code
lListFile is string
lListFile = HListFile(hLstNormal)
lStringCount is int = StringCount(lListFile,RC)
lFileNumber is int
lFileName is string
lClassName is string
FOR lFileNumber = 1 TO lStringCount
lFileName = ExtractString(lListFile,lFileNumber,RC)
lClassName = "FM_"+lFileName
lClassName is class
Inherit from FileManager
END
END

Hi,
I am not sure what you want to do, but according to me you're mixing up OO and procedural ways of thinking.
First of all I think in WinDev you should create a seperate class "FileName" which inherits the members and methods from a parent class called "FileManager" although this doesn't sound logical based on the naming.
Next for each file you retrieved using hListFile(), you instantiate an instance of FileName.
But designwise (based on your naming used in the code snippet) I think it would be better if you instantiate an instance of the "FileManager" class which contains an array containg "File" instances objects from a "File" class as a member.
Anyway, these are just my 2 eurocents...
Cheers,
P.
Publicado el 02,abril 2005 - 20:54
Hi Jonathan,
IMO, you can do this using dynamic compile. See Compile and ExecuteProcess as a first step.
Regards
Raimund
Hello,
How can i create a class based on a name in a variable?
The "lClassName is class" gives a error
i have also tried "{lClassName} is class"
Here is some code
lListFile is string
lListFile = HListFile(hLstNormal)
lStringCount is int = StringCount(lListFile,RC)
lFileNumber is int
lFileName is string
lClassName is string
FOR lFileNumber = 1 TO lStringCount
lFileName = ExtractString(lListFile,lFileNumber,RC)
lClassName = "FM_"+lFileName
lClassName is class
Inherit from FileManager
END
END



http://www.invitec.com
Publicado el 03,abril 2005 - 17:12
>Next for each file you retrieved using hListFile(), you instantiate an instance of FileName.

Here is my point!.... how can i instantie a instance based on a vaiable??
In the OO way it is smarter to let Windev generate the instance instead of typing a instance for each file in the analyse...
And later i want to use the Filemanager class in other projects..
Publicado el 03,abril 2005 - 21:49
Next for each file you retrieved using hListFile(), you instantiate an instance of FileName.

Here is my point!.... how can i instantie a instance based on a vaiable??
In the OO way it is smarter to let Windev generate the instance instead of typing a instance for each file in the analyse...
And later i want to use the Filemanager class in other projects..

By using a method AddFile(sFileNameVariable) in your FileManager class?
Peter!....
Publicado el 03,abril 2005 - 23:42
I think that we mis-understand each other...
I want to write a filemanager class for several file functions like
Next (with error handling)
Previous
Open
Close
Delete
Primefields
etc etc..
In the OO way you have to write a class once and use them (inherit) a lot...
I don't want to write (inherit) code for each file in the analyse.
I want to inherit the filmanager class based on a variable name for each file
the result should be... (file1 and file2 are fake name and should be replaced for each file in the analyse)
FM_file1 is a filemanager
FM_file2 is a filemanager
In the code i can use
FM_file1.open()
FM_file1.primfield(Field to prime)
FM_File1.autonumber(Key)
etc etc...
Next for each file you retrieved using hListFile(), you instantiate an instance of FileName.

Here is my point!.... how can i instantie a instance based on a vaiable??
In the OO way it is smarter to let Windev generate the instance instead of typing a instance for each file in the analyse...
And later i want to use the Filemanager class in other projects..
By using a method AddFile(sFileNameVariable) in your FileManager class?

Peter!....
Publicado el 04,abril 2005 - 01:43
I think that we mis-understand each other...
I want to write a filemanager class for several file functions like
Next (with error handling)
Previous
Open
Close
Delete
Primefields
etc etc..
In the OO way you have to write a class once and use them (inherit) a lot...
I don't want to write (inherit) code for each file in the analyse.
I want to inherit the filmanager class based on a variable name for each file
the result should be... (file1 and file2 are fake name and should be replaced for each file in the analyse)
FM_file1 is a filemanager
FM_file2 is a filemanager
In the code i can use
FM_file1.open()
FM_file1.primfield(Field to prime)
FM_File1.autonumber(Key)
etc etc...

Hi,
First of all I still think you are messing up OO and procedural ways of thinking here.
First of all to your statement:
"In the OO way you have to write a class once and use them (inherit) a lot..."
No, in an OO way a class inherits from a parent class and this can continue infinitely. Typically the "Circle" and "Square" classes inherit from the "Shape" class. Other examples: "MotorBoat" and "SailBoat" inherit from "Boat", "Car" and "Truck" inherit from "RoadVehicules" and "Boat" and "RoadVehicules" may inherit from "TransportionMeans", ... We are talking about the class definitions here.
So typically you will have a class "FileManager" with a member (=variable!!!)referring to the file you are treating.

FileManager is class
GLOBAL
FileName is string
END

Now add to the constructor of the class a parameter say "pFileName" and assign this parameter to the sFileName member.

Procedure Constructor(pFileName)
:sFileName=pFileName

Alternatively you can skip the parameter in the constructor and assign the member directly to the class instance once you have instantiated the class.
Now already you can instantiate as many FileManager objects (=instances) as you like.
FM_file1 is a filemanager("FileName1")
FM_file2 is a filemanager("FileName2")
Next in your class code use the great and famous W-Language indirection features to make your code independent of the filename. You stored this in the class member :sFileName; remember?
This should allow anything you want to do...
So, what I would suggest is to do some reading on OO and on the W-language indirection features.
One of the great advantages of OO is encapsulation. Use it!
I hope this helps you out.
Cheers,
P.

http://members.chello.be/cr45693/
Miembro registrado
71 mensajes
Publicado el 05,febrero 2018 - 21:16
Hello J.,

I know it is very long time ago, but did you ever solve this issue?

I found some ways how to achieve this in c# but it did not help me.

Kind regards

Petr