Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Several Questions about Component Creation

Status
Not open for further replies.

Leroy1981

Programmer
Jul 22, 2002
46
US
I have several questions about component creation

1.How do I overload the +-/* operators for components? I tried

ComponentName __fastcall operator+(ComponentName Value);
ComponentName* __fastcall operator+(ComponentName* Value);
ComponentName& __fastcall operator+(ComponentName& Value);

But when I test it I get the compile time error:Invalid Pointer Addition or something like that.

2.I have a property editor class that is registering fine but I still don't know how to get the actual values of the property being edited into the property editor.

3.My property editor class registers fine and I have overriden the Edit method right, but how do I make a dialog appear when Edit is invoked? I've managed to use the designer parameter that is passed to the constructor and use it's ContainerWindow property to add components to the form but I would have to run the program in order to make use of these components.

4.Is it possible to create events with extra parameters other than the Sender parameter?

5.Can someone help me specify the bitmap that is displayed
on the component pallette? There is only a half page of info int the help section and it still doesn't work when I follow everything it says. Any info would be appreciated.

Thanx in advance.
 
Oh boy! I'll try to answer what I know, but component creation takes a lot of patience. And I'm no expert, but I do build components on a regular basis.

1) this one I'm not too sure on. It seems like you want to be able to do something like this:

comp1 = comp2+comp3;

If your components are dynamically allocated, yeah, you'll get invalid pointer additions. Either use static allocation or dereference your objects before adding them. Of course, I may be off base because you haven't given the line of code that causes the error.

2) Do you call one of the 'Set' methods to set the value into the property editor? Do you override the SetValue() and/or GetValue() methods?

3) Inside your Edit() method, just create a new form and show it (modally I would think is best). When you're done, just delete it. Use GetComponent(int index) to get the list of components being edited. Not sure what you're asking really.

4) Sure it is!

Just define a type for your event. Here's an example from an audio component I wrote (it's an event that gets triggered when play stops):

typedef void __fastcall (__closure *TEndPlay)(TObject *Sender, int ms);

Add whatever arguments you want after Sender. I used 'ms' for the number of milliseconds that it was playing. In the above case, TEndPlay is the type, so just rename it to whatever you like.

In the private section, I store my event pointer.
TEndPlay EndPlay;

In the __published section, I define the property so that I can set this event in the property editor at design time.

__property TEndPlay OnEndPlay = {read = EndPlay, write = EndPlay};

Now "OnEndPlay" will show up in the events section of the property editor.

When the component is done playing, it will do the following to trigger the event:

if (EndPlay!=NULL) EndPlay(this, play_length);

oh yeah, don't forget to set it to NULL in your constructor or where ever you validate the values in case it doesn't get set.

5) I had a lot of problems with this as well.

You probably created a .dcr resource file and put your image in it, yet it still doesn't show up right? I'll just go over the steps again and then explain how to fix any remaining problems.

First off, I was unable to get 256 or more color bitmaps to work with the image editor that comes with Borland even though there is an option for it. For 256 or more color bitmaps, I would use another resource editor, but you may have more luck than I. Try 16 colors first as a test. NOTE: Borland probably will display 256 colors or more in its palette, but writing out the resource file is another story.

So you create a resource with the exact same name as your .cpp file that contains the component in question, but with a .dcr extension.

Inside this dcr file, create a bitmap with a name (all caps, but shouldn't matter) that matches your class name exactly.

you'll have to do the above for all your components. So you'll end up with many .dcr files.

Recompile your project. ie. BUILD not make.

Make sure that your project copies the .bpl file into borland's bin or projects\bpl directories. Also make sure that the .lib and .bpi files are in borland's lib or projects\lib directories.

You can set these options in your project options dialog under directories/final output (for .bpl) and bpi/lib output settings.

If they still don't show up, you may have to uninstall the component and close builder to get the component out of the operating systems cache. Remember, these components are DLL's and if anything on the system continues using them, they won't get unloaded and won't update no matter how many times you recompile. That's why closing Builder is sometimes necessary.

Go into the bin,bpl and lib directories mentioned above and manually DELETE all files that are from your components (ie. the .lib, .bpi and .bpl files with your project name). Then relaunch builder and BUILD the component (yes, recompile everything). Then install the component and it should show up. Make sure the .lib, .bpi and .bpl files are in the right places.


Well, I'm exhausted now. ;)

Cheers



A programmer is a device for converting Coke into software.
 
How exactly do you statically allocate components? When I try to do this this I get an error saying that vcl classes
must be constructed using new. Plus, dereferencing the pointers every time you want to add 2 components would undermine the benefits of operator overloading would'nt it?
 
Yeah, sorry. You can't statically allocate a VCL component. I was thinking in terms of general class creation. Using operator overloading on components isn't something I've ever seen done and I'm not sure if it's advisable.

Yeah, dereferencing components would look ugly. But I think that's the point. I haven't ever had the need to do this, but have you tried assigning your objects to reference variables? That should work, although I'm not sure if the VCL puts limitations on operator overloading. You may want to ask about operator overloading in a C++ only forum.

BTW, yes, dereferencing 2 pointers every time you want to add the components they point to would undermine the benefits as far as it applies to pointers to objects... and it should! When you start changing the way things work on primitive types (especially pointers), you're asking for trouble.



A programmer is a device for converting Coke into software.
 
Thanks for the info. I guess I'll just get used to not using operators with my components.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top