mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 20:49:19 +02:00
* Implemented THTMLDatasetFormProducer.AfterSetRecord
* Fixed some compiler-warnings * Fixed possible AV * When a label also is a link, really make a link * Removed (almost) duplicate code in PlaceFieldValue git-svn-id: trunk@12974 -
This commit is contained in:
parent
986553771d
commit
8ffb1a751e
@ -32,6 +32,7 @@ type
|
|||||||
Button : THTMLAttrsElement) of object;
|
Button : THTMLAttrsElement) of object;
|
||||||
TProducerEvent = procedure (Sender:THTMLDatasetFormProducer; FieldDef:TFormFieldItem;
|
TProducerEvent = procedure (Sender:THTMLDatasetFormProducer; FieldDef:TFormFieldItem;
|
||||||
Producer:THTMLContentProducer) of object;
|
Producer:THTMLContentProducer) of object;
|
||||||
|
TProducerSetRecordEvent = procedure (Sender:THTMLDatasetFormProducer) of object;
|
||||||
THTMLElementEvent = procedure (Sender:THTMLDatasetFormProducer; element : THTMLCustomElement) of object;
|
THTMLElementEvent = procedure (Sender:THTMLDatasetFormProducer; element : THTMLCustomElement) of object;
|
||||||
TFieldCheckEvent = procedure (aField:TField; var check:boolean) of object;
|
TFieldCheckEvent = procedure (aField:TField; var check:boolean) of object;
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ type
|
|||||||
protected
|
protected
|
||||||
procedure AssignTo(Dest: TPersistent); override;
|
procedure AssignTo(Dest: TPersistent); override;
|
||||||
Function GetDisplayName : String; override;
|
Function GetDisplayName : String; override;
|
||||||
Procedure SetDisplayName(AValue : String);
|
Procedure SetDisplayName(const Value : String); override;
|
||||||
public
|
public
|
||||||
constructor Create(ACollection: TCollection); override;
|
constructor Create(ACollection: TCollection); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -271,6 +272,7 @@ type
|
|||||||
|
|
||||||
THTMLDatasetFormProducer = class (THTMLContentProducer)
|
THTMLDatasetFormProducer = class (THTMLContentProducer)
|
||||||
private
|
private
|
||||||
|
FAfterSetRecord: TProducerSetRecordEvent;
|
||||||
FOnInitializeProducer : TProducerEvent;
|
FOnInitializeProducer : TProducerEvent;
|
||||||
FOnFieldChecked : TFieldCheckEvent;
|
FOnFieldChecked : TFieldCheckEvent;
|
||||||
FAfterTBodyCreate,
|
FAfterTBodyCreate,
|
||||||
@ -299,8 +301,8 @@ type
|
|||||||
procedure CorrectCellSpans;
|
procedure CorrectCellSpans;
|
||||||
procedure SearchControlFields;
|
procedure SearchControlFields;
|
||||||
protected
|
protected
|
||||||
function WriteContent (aWriter : THTMLWriter) : THTMLCustomElement; override;
|
|
||||||
procedure FillTableDef (IsHeader:boolean); virtual;
|
procedure FillTableDef (IsHeader:boolean); virtual;
|
||||||
|
procedure PlaceFieldValue(aControldef : TFormFieldItem); virtual;
|
||||||
procedure ControlToTableDef (aControldef : TFormFieldItem; IsHeader:boolean); virtual; abstract;
|
procedure ControlToTableDef (aControldef : TFormFieldItem; IsHeader:boolean); virtual; abstract;
|
||||||
function StartForm (aWriter : THTMLWriter) : THTMLCustomElement; virtual;
|
function StartForm (aWriter : THTMLWriter) : THTMLCustomElement; virtual;
|
||||||
procedure EndForm (aWriter : THTMLWriter); virtual;
|
procedure EndForm (aWriter : THTMLWriter); virtual;
|
||||||
@ -316,6 +318,7 @@ type
|
|||||||
public
|
public
|
||||||
constructor create (aOwner : TComponent); override;
|
constructor create (aOwner : TComponent); override;
|
||||||
destructor destroy; override;
|
destructor destroy; override;
|
||||||
|
function WriteContent (aWriter : THTMLWriter) : THTMLCustomElement; override;
|
||||||
published
|
published
|
||||||
property FormAction : string read FFormAction write FFormAction;
|
property FormAction : string read FFormAction write FFormAction;
|
||||||
// action of the form (link), if not given; don't use a form element
|
// action of the form (link), if not given; don't use a form element
|
||||||
@ -347,6 +350,8 @@ type
|
|||||||
// Called after the creation of the table
|
// Called after the creation of the table
|
||||||
property AfterTBodyCreate : THTMLElementEvent read FAfterTBodyCreate write FAfterTBodyCreate;
|
property AfterTBodyCreate : THTMLElementEvent read FAfterTBodyCreate write FAfterTBodyCreate;
|
||||||
// Called after finishing the tbody of each record
|
// Called after finishing the tbody of each record
|
||||||
|
property AfterSetRecord : TProducerSetRecordEvent read FAfterSetRecord write FAfterSetRecord;
|
||||||
|
// Called after the dataset is scrolled to the next record
|
||||||
property OnFieldChecked : TFieldCheckEvent read FOnFieldChecked write FOnFieldChecked;
|
property OnFieldChecked : TFieldCheckEvent read FOnFieldChecked write FOnFieldChecked;
|
||||||
// return if the field is true or false if the false string differs from '0','false','-'
|
// return if the field is true or false if the false string differs from '0','false','-'
|
||||||
end;
|
end;
|
||||||
@ -376,6 +381,7 @@ type
|
|||||||
property RecordsPerPage;
|
property RecordsPerPage;
|
||||||
property Page;
|
property Page;
|
||||||
property IncludeHeader;
|
property IncludeHeader;
|
||||||
|
property AfterSetRecord;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -481,10 +487,10 @@ begin
|
|||||||
Result:=FName;
|
Result:=FName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFormFieldItem.SetDisplayName(AValue: String);
|
procedure TFormFieldItem.SetDisplayName(const Value: String);
|
||||||
begin
|
begin
|
||||||
Inherited;
|
Inherited;
|
||||||
FName:=AValue;
|
FName:=Value;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TFormFieldItem.Create(ACollection: TCollection);
|
constructor TFormFieldItem.Create(ACollection: TCollection);
|
||||||
@ -791,7 +797,6 @@ end;
|
|||||||
procedure THTMLDatasetFormProducer.CorrectCellSpans;
|
procedure THTMLDatasetFormProducer.CorrectCellSpans;
|
||||||
var r, s, t : integer;
|
var r, s, t : integer;
|
||||||
c : TTableCell;
|
c : TTableCell;
|
||||||
ReachedEnd : boolean;
|
|
||||||
begin
|
begin
|
||||||
for r := 0 to TableDef.count-1 do
|
for r := 0 to TableDef.count-1 do
|
||||||
with TableDef.items[r] do
|
with TableDef.items[r] do
|
||||||
@ -898,6 +903,8 @@ begin
|
|||||||
r := 0;
|
r := 0;
|
||||||
while not eof and (r < RecordsPerPage) do
|
while not eof and (r < RecordsPerPage) do
|
||||||
begin
|
begin
|
||||||
|
if assigned (FAfterSetRecord) then
|
||||||
|
FAfterSetRecord (self);
|
||||||
FillTableDef (false);
|
FillTableDef (false);
|
||||||
CorrectCellSpans;
|
CorrectCellSpans;
|
||||||
WriteTableDef (aWriter);
|
WriteTableDef (aWriter);
|
||||||
@ -921,35 +928,9 @@ begin
|
|||||||
ControlToTableDef (Controls.items[r], IsHeader);
|
ControlToTableDef (Controls.items[r], IsHeader);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function THTMLDatasetFormProducer.SingleRecord: boolean;
|
procedure THTMLDatasetFormProducer.PlaceFieldValue(aControldef : TFormFieldItem);
|
||||||
|
var check : boolean;
|
||||||
begin
|
begin
|
||||||
result := true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
constructor THTMLDatasetFormProducer.create(aOwner: TComponent);
|
|
||||||
begin
|
|
||||||
inherited create(aOwner);
|
|
||||||
FTableCols := 2;
|
|
||||||
FButtonsHor := bhpLeft;
|
|
||||||
FButtonsVer := [bvpTop, bvpBottom];
|
|
||||||
Fbuttonrow := TFormButtonCollection.create;
|
|
||||||
FControls := TFormFieldCollection.Create;
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor THTMLDatasetFormProducer.destroy;
|
|
||||||
begin
|
|
||||||
Fbuttonrow.Free;
|
|
||||||
FControls.Free;
|
|
||||||
inherited destroy;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ THTMLDatasetFormEditProducer }
|
|
||||||
|
|
||||||
procedure THTMLDatasetFormEditProducer.ControlToTableDef (aControldef : TFormFieldItem; IsHeader:boolean);
|
|
||||||
|
|
||||||
procedure PlaceFieldValue;
|
|
||||||
var check : boolean;
|
|
||||||
begin
|
|
||||||
with TableDef.CopyTablePosition(aControlDef.ValuePos) do
|
with TableDef.CopyTablePosition(aControlDef.ValuePos) do
|
||||||
begin
|
begin
|
||||||
FormField := aControldef;
|
FormField := aControldef;
|
||||||
@ -981,18 +962,46 @@ procedure THTMLDatasetFormEditProducer.ControlToTableDef (aControldef : TFormFie
|
|||||||
begin
|
begin
|
||||||
CellType := ctProducer;
|
CellType := ctProducer;
|
||||||
Producer := aControlDef.Producer;
|
Producer := aControlDef.Producer;
|
||||||
|
// if Producer is THTMLSelectProducer then THTMLSelectProducer(Producer).PreSelected:=aControldef.getValue;
|
||||||
end;
|
end;
|
||||||
fitrecordselection : ;
|
fitrecordselection : ;
|
||||||
end;
|
end;
|
||||||
IsLabel := false;
|
IsLabel := false;
|
||||||
Value := aControlDef.getValue;
|
Value := aControlDef.getValue;
|
||||||
|
Link := aControldef.getAction;
|
||||||
if not FSeparateLabel and not FIncludeHeader then
|
if not FSeparateLabel and not FIncludeHeader then
|
||||||
begin
|
begin
|
||||||
Caption := aControldef.getLabel;
|
Caption := aControldef.getLabel;
|
||||||
IncludeBreak := aControldef.LabelAbove;
|
IncludeBreak := aControldef.LabelAbove;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function THTMLDatasetFormProducer.SingleRecord: boolean;
|
||||||
|
begin
|
||||||
|
result := true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor THTMLDatasetFormProducer.create(aOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited create(aOwner);
|
||||||
|
FTableCols := 2;
|
||||||
|
FButtonsHor := bhpLeft;
|
||||||
|
FButtonsVer := [bvpTop, bvpBottom];
|
||||||
|
Fbuttonrow := TFormButtonCollection.create;
|
||||||
|
FControls := TFormFieldCollection.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor THTMLDatasetFormProducer.destroy;
|
||||||
|
begin
|
||||||
|
Fbuttonrow.Free;
|
||||||
|
FControls.Free;
|
||||||
|
inherited destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ THTMLDatasetFormEditProducer }
|
||||||
|
|
||||||
|
procedure THTMLDatasetFormEditProducer.ControlToTableDef (aControldef : TFormFieldItem; IsHeader:boolean);
|
||||||
|
|
||||||
procedure PlaceLabel;
|
procedure PlaceLabel;
|
||||||
begin
|
begin
|
||||||
@ -1007,7 +1016,7 @@ procedure THTMLDatasetFormEditProducer.ControlToTableDef (aControldef : TFormFie
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
if assigned (aControlDef.FField) then
|
if assigned (aControlDef.FField) then
|
||||||
PlaceFieldValue;
|
PlaceFieldValue(aControldef);
|
||||||
if FSeparateLabel and (aControlDef.getLabel <> '') then
|
if FSeparateLabel and (aControlDef.getLabel <> '') then
|
||||||
PlaceLabel;
|
PlaceLabel;
|
||||||
end;
|
end;
|
||||||
@ -1102,35 +1111,6 @@ end;
|
|||||||
|
|
||||||
procedure THTMLDatasetFormGridProducer.ControlToTableDef (aControldef : TFormFieldItem; IsHeader:boolean);
|
procedure THTMLDatasetFormGridProducer.ControlToTableDef (aControldef : TFormFieldItem; IsHeader:boolean);
|
||||||
|
|
||||||
procedure PlaceFieldValue;
|
|
||||||
var check : boolean;
|
|
||||||
begin
|
|
||||||
with TableDef.CopyTablePosition(aControlDef.ValuePos) do
|
|
||||||
begin
|
|
||||||
if aControldef.InputType = fitcheckbox then
|
|
||||||
begin
|
|
||||||
CellType := ctInput;
|
|
||||||
InputType := aControldef.InputType;
|
|
||||||
Disabled := True;
|
|
||||||
with aControlDef.Field do
|
|
||||||
Check := asBoolean;
|
|
||||||
if assigned (FOnFieldChecked) then
|
|
||||||
FOnFieldChecked (aControlDef.Field, check);
|
|
||||||
Checked := check;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
CellType := ctLabel;
|
|
||||||
IsLabel := false;
|
|
||||||
Value := aControlDef.getValue;
|
|
||||||
Link := aControldef.getAction;
|
|
||||||
if not FSeparateLabel and not FIncludeHeader then
|
|
||||||
begin
|
|
||||||
Caption := aControldef.getLabel;
|
|
||||||
IncludeBreak := aControldef.LabelAbove;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure PlaceLabel;
|
procedure PlaceLabel;
|
||||||
begin
|
begin
|
||||||
with TableDef.CopyTablePosition(aControlDef.LabelPos) do
|
with TableDef.CopyTablePosition(aControlDef.LabelPos) do
|
||||||
@ -1143,7 +1123,7 @@ procedure THTMLDatasetFormGridProducer.ControlToTableDef (aControldef : TFormFie
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
if assigned (aControlDef.FField) and not IsHeader then
|
if assigned (aControlDef.FField) and not IsHeader then
|
||||||
PlaceFieldValue;
|
PlaceFieldValue(aControldef);
|
||||||
if (IsHeader or FSeparateLabel) and (aControlDef.getLabel <> '') then
|
if (IsHeader or FSeparateLabel) and (aControlDef.getLabel <> '') then
|
||||||
PlaceLabel;
|
PlaceLabel;
|
||||||
end;
|
end;
|
||||||
@ -1215,13 +1195,16 @@ function TTableCell.WriteContent(aWriter: THTMLWriter) : THTMLCustomElement;
|
|||||||
fithidden :
|
fithidden :
|
||||||
aWriter.FormHidden (Name, Value);
|
aWriter.FormHidden (Name, Value);
|
||||||
fitlabel :
|
fitlabel :
|
||||||
|
if link <> '' then
|
||||||
|
aWriter.Anchor(Value).href := Link
|
||||||
|
else
|
||||||
aWriter.Text (Value);
|
aWriter.Text (Value);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure WriteProducer;
|
procedure WriteProducer;
|
||||||
begin
|
begin
|
||||||
with Producer do
|
if assigned(Producer) then with Producer do
|
||||||
begin
|
begin
|
||||||
ParentElement := aWriter.CurrentElement;
|
ParentElement := aWriter.CurrentElement;
|
||||||
HTMLDocument := aWriter.Document;
|
HTMLDocument := aWriter.Document;
|
||||||
@ -1270,7 +1253,6 @@ end;
|
|||||||
|
|
||||||
function TTableCell.WriteHeader(aWriter: THTMLWriter) : THTMLCustomElement;
|
function TTableCell.WriteHeader(aWriter: THTMLWriter) : THTMLCustomElement;
|
||||||
var c : THTML_th;
|
var c : THTML_th;
|
||||||
s : string;
|
|
||||||
begin
|
begin
|
||||||
with aWriter do
|
with aWriter do
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user