My first version of this question may have been to specific, so I will try to ask in a more general way:
I have a frame with a component on it, let's say it's a TButton. After placing the frame on the form I change a property of the component, let's say I set the tag on the button to 100.
In the frames' constructor I would like to do something like this:
constructor TMyFrame.Create(AOwner: TComponent);
begin
inherited;
if Button1.Tag = 100
then DoSomething
else DoSomethingElse;
end;
I found out that at this time (during creation) the tag of the button is still 0. Can someone recommend another way to do this?
In our application there are several places where the users can enter SQL statements. To facilitate this we use 开发者_如何学Pythonthe SynEdit component. We have created a frame for this purpose, with some extended functionality.
Sometimes we need the data-aware version (TDBSYnEdit), and at other times we need the "regular" version (TSynEdit). We have solved this by having a pagecontrol on the frame, and switch to the correct page at design time. The tabs are hid, so the user has no idea this happens.
The problem is that sometimes our developers forget to set the correct page on the page control, or accidentaly selects the wrong page.
I wanted to fix this by adding the following code to the Create event on the frame
if DBSQLMemo.DataField > ''
then pcMemos.ActivePage := tsDataAware
else pcMemos.ActivePage := tsNonDataAware;
My theory was that if a developer set the datasource/datafield properties of the editor the frame should be used in "data-aware mode", and the data-aware editor should be visible. As it turns out, at the moment of creation these properties aren't set.
Does anyone have a good suggestion to how I should solve this problem?
How about overriding the "Loaded" procedures? Then, when all the child components are loaded, scan them for the one's you need?
e.g.
interface
...
protected
procedure Loaded; override;
...
implementation
procedure Loaded;
var
i: Integer;
begin
inherited;
for i := 0 to pred(Self.ComponentCount) do
if Self.Components[i] is TSynEdit then
begin
// do something
end;
end;
If the component you need isn't a direct descendant of the frame, you will need to scan the children of the children etc.
I would remove the embedded SynEdit from the frame and instead give the frame a property referring to a SynEdit instance. That way you don't always have an useless SynEdit instance and the user might even decide to use a SynEdit derivative you didn't even think of.
Another idea: How about creating the SynEdit in code instead of visually? (Depends on how much you want to change it via the form designer.) Then you could drop the PageControl and have only one editor instance per frame.
精彩评论