Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:37 am
by Craig Shearer >> Mon, 20 Mar 2000 21:48:24 GMT
Having thought about how to work around this, I've come up with a Control subclass that accomplishes this.
The idea is that if you build a control, you can store whatever you want on instances of the control painted on a form. Therefore, I've designed a control to do just this. The control is a subclass of BaseControl.
Basically, the idea is that you'd create a form called (say) ResourceForm. Then you'd paint BinaryContainer controls on the form - one for each resource you wanted to store in your schema. In the Painter, you can then use the control's property sheet to load a binary from a file and store it in the binary property on the control. When the form is saved, the binary's value will be saved in the control.
Then, when you want to access your resources at runtime, you use the following example method, on either app or global:
getResource(resourceName: String): Binary;
vars
f : ResourceForm;
ctrl : Control;begin
create f transient;
ctrl := f.getPropertyValue(resourceName).Control;
if ctrl <> null and ctrl.isKindOf(BinaryContainer) then
return ctrl.BinaryContainer.binary;
else
return null;
endif;
epilog
delete f;
end;
as in
vars
data : Binary;begin
data := app.getResource("binData");
// use the data retrieved from the schema's resources..
The above code creates an instance of the form, then attempts to find a BinaryContainer control based upon the name passed to it. If successful, it retrieves the value of the binary property off the control, and returns it. The form is then deleted.
How to make it work:
I have attached a .cls extract file with this post. To make it work in your schema, do the following:
1. Find the BaseControl class.
2. Add a new subclass - BinaryContainer (this is very important - if you just load the .cls file, it won't work!)
3. Use the schema load to locate and load the BinaryContainer.cls file (supplied)
Now, use the class change dialog to set up the control's design time Properties and Events as follows:
Properties: binary, description, name
Events: none
Now, go into the Painter and create your resource form. Paint a BinaryContainer control on your form. The control will be invisible at runtime, but has been designed to show the name of the control in the Painter. Go to the properties sheet and you'll see, on the specific tab, that is has a binary property. This shows the current value - whether it is null or contains binary data, and if you drop it down, you can select change to bring up a file open dialog to load a new file.
You can save your form and the binary data will be saved in the control with it. You can verify this by going to the class browser and looking at the instances of the BinaryContainer control - you should see your binary data stored on the control.
Then, you can implement a method on either your Application or Global subclass (or whereever else!) to get at the resource at runtime.
Enjoy!
Craig.
-
Attachments
-
- 137_1.cls
- (4.39 KiB) Downloaded 256 times
Last edited by
ConvertFromOldNGs on Fri Aug 07, 2009 3:42 pm, edited 1 time in total.