I'm trying to create custom IW control. It's a simple <div>, but I want
to be able to set the "class" and "id" params. The result is different
from expected. The class and id params are always the name of the
control "CONTROLNAMECSS" and "CONTROLNAME".
Example:
<div tabindex="7" name="MYMESSAGEBOX" id="MYMESSAGEBOX" style="z-index:
100;" class="MYMESSAGEBOXCSS">Не е намерен ремонт и/ или устройство.</div>
Actually I find a way to override the class and id params using the
OnHTMLTag event. But don't like this solution.
Is there a way to set these params at RenderHTML function? I'm missing
something.
TIWDiv = class(TIWControl)
private
FClass: String;
FId : String;
FText : String;
procedure SetTextValue(const AValue: String);
public
constructor Create(AOwner: TComponent); override;
function RenderHTML(AContext: TIWBaseHTMLComponentContext):
TIWHTMLTag; override;
public
property CSSClass : String write SetTextValue;
property CSSId : String write SetTextValue;
property Text : String read FText write SetTextValue;
end;
constructor TIWDiv.Create(AOwner: TComponent);
begin
inherited;
FClass:= '';
FId := '';
FText := '';
end;
function TIWDiv.RenderHTML(AContext: TIWBaseHTMLComponentContext):
TIWHTMLTag;
begin
Result:= TIWHTMLTag.CreateTag('div');
Result.Params.Clear;
Result.AddStringParam('class', FClass);
Result.AddStringParam('id', FId);
Result.Contents.AddText(FText);
end;
procedure TIWDiv.SetTextValue(const AValue: String);
begin
FText:= AValue;
end;
....
procedure TMainForm.IWAppFormCreate(Sender: TObject);
begin
divMessageBox:= TIWDiv.Create(Self);
divMessageBox.Parent:= Self;
divMessageBox.Name:= 'MyMessageBox';
divMessageBox.FriendlyName:= 'MyMessageBox';
divMessageBox.Font.Enabled:= False;
divMessageBox.Show;
end;
procedure TMainForm.btnSearchDeviceClick(Sender: TObject);
var
ErrMsg, RepId, DevNumb: String;
begin
ErrMsg:= 'uMain > btnSearchDeviceClick > ';
RepId := Trim(edtRepairNumb.Text);
DevNumb := Trim(edtDevSerialNumb.Text);
divMessageBox.CSSClass:= 'message-box';
if (RepId = '') OR (StrToIntDef(RepId, -1) < 1) then begin
divMessageBox.CSSId:= 'fail';
divMessageBox.Text:= 'Не е намерен ремонт и/ или устройство.';
//lblStatus.Text:= 'Не е намерен ремонт и/ или устройство.';
//lblStatus.Font.CSSStyle:= 'red_fail';
Exit;
end;
....
end;