{----------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: JvFormToHtml.PAS, released on 2001-02-28. The Initial Developer of the Original Code is Sébastien Buysse [sbuysse att buypin dott com] Portions created by Sébastien Buysse are Copyright (C) 2001 Sébastien Buysse. All Rights Reserved. Contributor(s): Michael Beck [mbeck att bigfoot dott com]. You may retrieve the latest version of this file at the Project JEDI's JVCL home page, located at http://jvcl.delphi-jedi.org Known Issues: -----------------------------------------------------------------------------} // $Id$ unit JvFormToHtml; {$mode objfpc}{$H+} interface uses SysUtils, Classes, Graphics, Controls, Forms, StdCtrls; // JvComponentBase; type TJvFormToHtml = class(TComponent) //TJvComponent) public procedure FormToHtml(const Form: TCustomForm; const Filename: string); procedure FormToHtml(const Form: TCustomForm; HTML: TStrings); end; implementation function FontToCss(const Font: TFont): string; begin Result := Format(';font-Size:%d;color:#%d;font-weight:', [Font.Size, Font.Color]); if fsBold in Font.Style then Result := Result + 'bold;' else Result := Result + 'normal;'; Result := Result + 'font-family:' + Font.Name; end; procedure TJvFormToHtml.FormToHtml(const Form: TCustomForm; const Filename: string); var HTML: TStringList; begin HTML := TStringList.Create; try FormToHTML(Form, HTML); HTML.SaveToFile(FileName); finally HTML.Free; end; end; procedure TJvFormToHtml.FormToHtml(const Form: TCustomForm; HTML: TStrings); var I, J: Integer; C: TComponent; S, S2, St: string; begin if HTML = nil then exit; HTML.Add('
'); for I := 0 to Form.ComponentCount - 1 do begin C := Form.Components[I]; St := ''; if C is TLabel then begin St := Format(''; end else if C is TButton then begin if not TButton(C).Enabled then S := ' DISABLED' else S := ''; St := Format(''; end else if C is TMemo then begin S := ''; if TMemo(C).ReadOnly then S := S + ' ReadOnly'; if not TMemo(C).Enabled then S := S + ' DISABLED'; S2 := ''; if TMemo(C).WordWrap then S2 := S2 + ' WRAP=PHYSICAL' else S2 := S2 + ' WRAP=OFF'; St := Format(''; end else if C is TCheckBox then begin S := ''; if not TCheckBox(C).Enabled then S := S + ' DISABLED'; if TCheckBox(C).Checked then S := S + ' CHECKED'; St := Format(''; HTML.Add(St); St := Format(''; end else if C is TRadioButton then begin S := ''; if not TRadioButton(C).Enabled then S := S + ' DISABLED'; if TRadioButton(C).Checked then S := S + ' CHECKED'; St := Format(''; HTML.Add(St); St := Format(''; end else if C is TEdit then begin S := ''; if TEdit(C).ReadOnly then S := S + ' ReadOnly'; if TEdit(C).MaxLength <> 0 then S := S + ' MAXLENGTH=' + IntToStr(TEdit(C).MaxLength); if not TEdit(C).Enabled then S := S + ' DISABLED'; St := Format(''; end else if C is TComboBox then begin if not TComboBox(C).Enabled then S := ' DISABLED' else S := ''; St := Format(''; end else if C is TListBox then begin if not TListBox(C).Enabled then S := ' DISABLED' else S := ''; St := Format(''; end; if St <> '' then HTML.Add(St); end; HTML.Add(''); end; end.