12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258 |
- {
- $Id$
- This file is part of the Free Pascal run time library.
- Copyright (c) 1999-2000 by Michael Van Canneyt, member of the
- Free Pascal development team
- TFields and related components implementations.
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- Procedure DumpMem (P : Pointer;Size : Longint);
- Var i : longint;
- begin
- Write ('Memory dump : ');
- For I:=0 to Size-1 do
- Write (Pbyte(P)[i],' ');
- Writeln;
- end;
- { ---------------------------------------------------------------------
- TFieldDef
- ---------------------------------------------------------------------}
- Constructor TFieldDef.Create(AOwner: TFieldDefs; const AName: string;
- ADataType: TFieldType; ASize: Word; ARequired: Boolean; AFieldNo: Longint);
- begin
- Inherited Create(AOwner);
- {$ifdef dsdebug }
- Writeln('TFieldDef.Create : ',Aname,'(',AFieldNo,')');
- {$endif}
- FName:=Aname;
- FDatatype:=ADatatype;
- FSize:=ASize;
- FRequired:=ARequired;
- FPrecision:=-1;
- // Correct sizes.
- If FDataType=ftFloat then
- begin
- If Not (FSize in [4,8,10]) then FSize:=10
- end
- else If FDataType in [ftWord,ftsmallint,ftinteger] Then
- If Not (FSize in [1,2,4]) then FSize:=4;
- FFieldNo:=AFieldNo;
- AOwner.FItems.Add(Self);
- end;
- Destructor TFieldDef.Destroy;
- Var I : longint;
- begin
- Inherited destroy;
- end;
- Function TFieldDef.CreateField(AOwner: TComponent): TField;
- Var TheField : TFieldClass;
- begin
- {$ifdef dsdebug}
- Writeln ('Creating field '+FNAME);
- {$endif dsdebug}
- TheField:=GetFieldClass;
- if TheField=Nil then
- DatabaseErrorFmt(SUnknownFieldType,[FName]);
- Result:=Thefield.Create(AOwner);
- Try
- Result.Size:=FSize;
- Result.Required:=FRequired;
- Result.FieldName:=FName;
- Result.FFieldNo:=Self.FieldNo;
- Result.SetFieldType(DataType);
- {$ifdef dsdebug}
- Writeln ('TFieldDef.CReateField : Trying to set dataset');
- {$endif dsdebug}
- {$ifdef dsdebug}
- Writeln ('TFieldDef.CReateField : Result Fieldno : ',Result.FieldNo,' Self : ',FieldNo);
- {$endif dsdebug}
- Result.Dataset:=TFieldDefs(Owner).FDataset;
- If Result is TFloatField then
- TFloatField(Result).Precision:=FPrecision;
- except
- Result.Free;
- Raise;
- end;
- end;
- Function TFieldDef.GetFieldClass : TFieldClass;
- begin
- //!! Should be owner as tdataset but that doesn't work ??
- If Assigned(Owner) then
- Result:=TFieldDefs(Owner).FDataSet.GetFieldClass(FDataType)
- else
- Result:=Nil;
- end;
- { ---------------------------------------------------------------------
- TFieldDefs
- ---------------------------------------------------------------------}
- destructor TFieldDefs.Destroy;
- begin
- FItems.Free;
- // This will destroy all fielddefs since we own them...
- Inherited Destroy;
- end;
- procedure TFieldDefs.Add(const AName: string; ADataType: TFieldType);
- begin
- Add(AName,ADatatype,0,False);
- end;
- procedure TFieldDefs.Add(const AName: string; ADataType: TFieldType; ASize : Word);
- begin
- Add(AName,ADatatype,ASize,False);
- end;
- procedure TFieldDefs.Add(const AName: string; ADataType: TFieldType; ASize: Word;
- ARequired: Boolean);
- begin
- If Length(AName)=0 Then
- DatabaseError(SNeedFieldName);
- // the fielddef will register itself here as a owned component.
- // fieldno is 1 based !
- TFieldDef.Create(Self,AName,ADataType,ASize,Arequired,FItems.Count+1);
- end;
- function TFieldDefs.GetCount: Longint;
- begin
- Result:=FItems.Count;
- end;
- function TFieldDefs.GetItem(Index: Longint): TFieldDef;
- begin
- Result:=TFieldDef(FItems[Index]);
- end;
- constructor TFieldDefs.Create(ADataSet: TDataSet);
- begin
- Inherited Create(ADataSet);
- FItems:=TList.Create;
- FDataset:=ADataset;
- end;
- procedure TFieldDefs.Assign(FieldDefs: TFieldDefs);
- Var I : longint;
- begin
- Clear;
- For i:=0 to FieldDefs.Count-1 do
- With FieldDefs[i] do
- Add(Name,DataType,Size,Required);
- end;
- procedure TFieldDefs.Clear;
- Var I : longint;
- begin
- For I:=FItems.Count-1 downto 0 do
- TFieldDef(Fitems[i]).Free;
- FItems.Clear;
- end;
- function TFieldDefs.Find(const AName: string): TFieldDef;
- Var I : longint;
- begin
- I:=IndexOf(AName);
- If I=-1 Then
- DataBaseErrorFmt(SUnknownField,[AName,FDataSet.Name]);
- Result:=TFieldDef(Fitems[i]);
- end;
- function TFieldDefs.IndexOf(const AName: string): Longint;
- Var I : longint;
- begin
- For I:=0 to Fitems.Count-1 do
- If AnsiCompareText(TFieldDef(FItems[I]).Name,AName)=0 then
- begin
- Result:=I;
- Exit;
- end;
- Result:=-1;
- end;
- procedure TFieldDefs.Update;
- begin
- FDataSet.UpdateFieldDefs;
- end;
- Function TFieldDefs.AddFieldDef : TFieldDef;
- begin
- Result:=TFieldDef.Create(Self,'',ftUnknown,0,False,FItems.Count+1);
- end;
- { ---------------------------------------------------------------------
- TField
- ---------------------------------------------------------------------}
- Const
- SBoolean = 'Boolean';
- SDateTime = 'TDateTime';
- SFloat = 'Float';
- SInteger = 'Integer';
- SVariant = 'Variant';
- SString = 'String';
- constructor TField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- FVisible:=True;
- FValidChars:=[#0..#155];
- FProviderFlags := [pfInUpdate,pfInWhere];
- end;
- destructor TField.Destroy;
- begin
- IF Assigned(FDataSet) then
- begin
- FDataSet.Active:=False;
- FDataSet.RemoveField(Self);
- end;
- Inherited Destroy;
- end;
- function TField.AccessError(const TypeName: string): EDatabaseError;
- begin
- Result:=EDatabaseError.CreateFmt(SinvalidTypeConversion,[TypeName,FFieldName]);
- end;
- procedure TField.Assign(Source: TPersistent);
- begin
- //!! To be implemented
- end;
- procedure TField.Change;
- begin
- If Assigned(FOnChange) Then
- FOnChange(Self);
- end;
- procedure TField.CheckInactive;
- begin
- If Assigned(FDataSet) then
- FDataset.CheckInactive;
- end;
- procedure TField.Clear;
- begin
- SetData(Nil);
- end;
- procedure TField.DataChanged;
- begin
- FDataset.DataEvent(deFieldChange,ptrint(Self));
- end;
- procedure TField.FocusControl;
- begin
- FDataSet.DataEvent(deFocusControl,ptrint(Self));
- end;
- procedure TField.FreeBuffers;
- begin
- // Empty. Provided for backward compatibiliy;
- // TDataset manages the buffers.
- end;
- function TField.GetAsBoolean: Boolean;
- begin
- AccessError(SBoolean);
- end;
- function TField.GetAsDateTime: TDateTime;
- begin
- AccessError(SdateTime);
- end;
- function TField.GetAsFloat: Double;
- begin
- AccessError(SDateTime);
- end;
- function TField.GetAsLongint: Longint;
- begin
- AccessError(SInteger);
- end;
- function TField.GetAsVariant: Variant;
- begin
- AccessError(SVariant);
- end;
- function TField.GetAsInteger: Integer;
- begin
- Result:=GetAsLongint;
- end;
- function TField.GetAsString: string;
- begin
- AccessError(SString);
- end;
- function TField.GetOldValue: Variant;
- var SaveState : tDatasetState;
- begin
- with FDataset do
- begin
- SaveState := State;
- SetTempState(dsOldValue);
- Result := GetAsVariant;
- RestoreState(SaveState);
- end;
- end;
- function TField.GetCanModify: Boolean;
- begin
- Result:=Not ReadOnly;
- If Result then
- begin
- Result:=Assigned(DataSet);
- If Result then
- Result:= DataSet.CanModify;
- end;
- end;
- function TField.GetData(Buffer: Pointer): Boolean;
- begin
- IF FDataset=Nil then
- DatabaseErrorFmt(SNoDataset,[FieldName]);
- If FVAlidating then
- begin
- result:=Not(FValueBuffer=Nil);
- If Result then
- Move (FValueBuffer^,Buffer^ ,DataSize);
- end
- else
- Result:=FDataset.GetFieldData(Self,Buffer);
- end;
- function TField.GetDataSize: Word;
- begin
- Result:=0;
- end;
- function TField.GetDefaultWidth: Longint;
- begin
- Result:=10;
- end;
- function TField.GetDisplayName : String;
- begin
- If FDisplayLabel<>'' then
- result:=FDisplayLabel
- else
- Result:=FFieldName;
- end;
- Function TField.IsDisplayStored : Boolean;
- begin
- Result:=(DisplayLabel<>FieldName);
- end;
- function TField.getIndex : longint;
- begin
- If Assigned(FDataset) then
- Result:=FDataset.FFieldList.IndexOf(Self)
- else
- Result:=-1;
- end;
- procedure TField.SetAlignment(const AValue: TAlignMent);
- begin
- if FAlignment <> AValue then
- begin
- FAlignment := Avalue;
- PropertyChanged(false);
- end;
- end;
- function TField.GetIsNull: Boolean;
- begin
- Result:=Not(GetData (Nil));
- end;
- function TField.GetParentComponent: TComponent;
- begin
- //!! To be implemented
- end;
- procedure TField.GetText(var AText: string; ADisplayText: Boolean);
- begin
- AText:=GetAsString;
- end;
- function TField.HasParent: Boolean;
- begin
- HasParent:=True;
- end;
- function TField.IsValidChar(InputChar: Char): Boolean;
- begin
- // FValidChars must be set in Create.
- Result:=InputChar in FValidChars;
- end;
- procedure TField.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- Inherited Notification(AComponent,Operation);
- end;
- procedure TField.PropertyChanged(LayoutAffected: Boolean);
- begin
- If (FDataset<>Nil) and (FDataset.Active) then
- If LayoutAffected then
- FDataset.DataEvent(deLayoutChange,0)
- else
- FDataset.DataEvent(deDatasetchange,0);
- end;
- procedure TField.ReadState(Reader: TReader);
- begin
- //!! To be implemented
- end;
- procedure TField.SetAsBoolean(AValue: Boolean);
- begin
- AccessError(SBoolean);
- end;
- procedure TField.SetAsDateTime(AValue: TDateTime);
- begin
- AccessError(SDateTime);
- end;
- procedure TField.SetAsFloat(AValue: Double);
- begin
- AccessError(SFloat);
- end;
- procedure TField.SetAsVariant(AValue: Variant);
- begin
- AccessError(SVariant);
- end;
- procedure TField.SetAsLongint(AValue: Longint);
- begin
- AccessError(SInteger);
- end;
- procedure TField.SetAsInteger(AValue: Integer);
- begin
- SetAsLongint(AValue);
- end;
- procedure TField.SetAsString(const AValue: string);
- begin
- AccessError(SString);
- end;
- procedure TField.SetData(Buffer: Pointer);
- begin
- If Not Assigned(FDataset) then
- EDatabaseError.CreateFmt(SNoDataset,[FieldName]);
- FDataSet.SetFieldData(Self,Buffer);
- end;
- Procedure TField.SetDataset (Value : TDataset);
- begin
- {$ifdef dsdebug}
- Writeln ('Setting dataset');
- {$endif}
- If Value=FDataset then exit;
- If Assigned(FDataset) Then
- begin
- FDataset.CheckInactive;
- FDataset.FFieldList.Remove(Self);
- end;
- If Assigned(Value) then
- begin
- Value.CheckInactive;
- Value.FFieldList.Add(Self);
- end;
- FDataset:=Value;
- end;
- procedure TField.SetDataType(AValue: TFieldType);
- begin
- FDataType := AValue;
- end;
- procedure TField.SetFieldType(AValue: TFieldType);
- begin
- //!! To be implemented
- end;
- procedure TField.SetParentComponent(AParent: TComponent);
- begin
- //!! To be implemented
- end;
- procedure TField.SetSize(AValue: Word);
- begin
- CheckInactive;
- CheckTypeSize(AValue);
- FSize:=AValue;
- end;
- procedure TField.SetText(const AValue: string);
- begin
- AsString:=AValue;
- end;
- procedure TField.Validate(Buffer: Pointer);
- begin
- If assigned(OnValidate) Then
- begin
- FValueBuffer:=Buffer;
- FValidating:=True;
- Try
- OnValidate(Self);
- finally
- FValidating:=False;
- end;
- end;
- end;
- class function Tfield.IsBlob: Boolean;
- begin
- Result:=False;
- end;
- class procedure TField.CheckTypeSize(AValue: Longint);
- begin
- If (AValue<>0) and Not IsBlob Then
- DatabaseErrorFmt(SInvalidFieldSize,[AValue]);
- end;
- // TField private methods
- function TField.GetDisplayText: String;
- begin
- SetLength(Result, 0);
- if Assigned(OnGetText) then
- OnGetText(Self, Result, True)
- else
- GetText(Result, True);
- end;
- procedure TField.SetDisplayLabel(const AValue: string);
- begin
- if FDisplayLabel<>Avalue then
- begin
- FDisplayLabel:=Avalue;
- PropertyChanged(true);
- end;
- end;
- procedure TField.SetDisplayWidth(const AValue: Longint);
- begin
- if FDisplayWidth<>AValue then
- begin
- FDisplayWidth:=AValue;
- PropertyChanged(True);
- end;
- end;
- function TField.GetDisplayWidth: integer;
- begin
- if FDisplayWidth=0 then
- result:=GetDefaultWidth
- else
- result:=FDisplayWidth;
- end;
- procedure TField.SetReadOnly(const AValue: Boolean);
- begin
- if (FReadOnly<>Avalue) then
- begin
- FReadOnly:=AValue;
- PropertyChanged(True);
- end;
- end;
- procedure TField.SetVisible(const AValue: Boolean);
- begin
- if FVisible<>Avalue then
- begin
- FVisible:=AValue;
- PropertyChanged(True);
- end;
- end;
- { ---------------------------------------------------------------------
- TStringField
- ---------------------------------------------------------------------}
- constructor TStringField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDataType(ftString);
- Size:=20;
- end;
- class procedure TStringField.CheckTypeSize(AValue: Longint);
- begin
- If (AValue<1) or (AValue>dsMaxStringSize) Then
- databaseErrorFmt(SInvalidFieldSize,[AValue])
- end;
- function TStringField.GetAsBoolean: Boolean;
- Var S : String;
- begin
- S:=GetAsString;
- result := (Length(S)>0) and (Upcase(S[1]) in ['T',YesNoChars[True]]);
- end;
- function TStringField.GetAsDateTime: TDateTime;
- begin
- Result:=StrToDateTime(GetAsString);
- end;
- function TStringField.GetAsFloat: Double;
- begin
- Result:=StrToFloat(GetAsString);
- end;
- function TStringField.GetAsLongint: Longint;
- begin
- Result:=StrToInt(GetAsString);
- end;
- function TStringField.GetAsString: string;
- begin
- If Not GetValue(Result) then
- Result:='';
- end;
- function TStringField.GetAsVariant: Variant;
- Var s : string;
- begin
- If GetValue(s) then
- Result:=s
- else
- Result:=Null;
- end;
- function TStringField.GetDataSize: Word;
- begin
- Result:=Size+1;
- end;
- function TStringField.GetDefaultWidth: Longint;
- begin
- result:=Size;
- end;
- Procedure TStringField.GetText(var AText: string; ADisplayText: Boolean);
- begin
- AText:=GetAsString;
- end;
- function TStringField.GetValue(var AValue: string): Boolean;
- Var Buf : TStringFieldBuffer;
- begin
- Result:=GetData(@Buf);
- If Result then
- AValue:=Buf;
- end;
- procedure TStringField.SetAsBoolean(AValue: Boolean);
- begin
- If AValue Then
- SetAsString('T')
- else
- SetAsString('F');
- end;
- procedure TStringField.SetAsDateTime(AValue: TDateTime);
- begin
- SetAsString(DateTimeToStr(AValue));
- end;
- procedure TStringField.SetAsFloat(AValue: Double);
- begin
- SetAsString(FloatToStr(AValue));
- end;
- procedure TStringField.SetAsLongint(AValue: Longint);
- begin
- SetAsString(intToStr(AValue));
- end;
- procedure TStringField.SetAsString(const AValue: string);
- Const NullByte : char = #0;
- begin
- IF Length(AValue)=0 then
- SetData(@NullByte)
- else
- SetData(@AValue[1]);
- end;
- { ---------------------------------------------------------------------
- TNumericField
- ---------------------------------------------------------------------}
- constructor TNumericField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- AlignMent:=taRightJustify;
- end;
- procedure TNumericField.RangeError(AValue, Min, Max: Double);
- begin
- DatabaseErrorFMT(SRangeError,[AValue,Min,Max,FieldName]);
- end;
- procedure TNumericField.SetDisplayFormat(const AValue: string);
- begin
- If FDisplayFormat<>AValue then
- begin
- FDisplayFormat:=AValue;
- PropertyChanged(True);
- end;
- end;
- procedure TNumericField.SetEditFormat(const AValue: string);
- begin
- If FEDitFormat<>AValue then
- begin
- FEDitFormat:=AVAlue;
- PropertyChanged(True);
- end;
- end;
- { ---------------------------------------------------------------------
- TLongintField
- ---------------------------------------------------------------------}
- constructor TLongintField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDatatype(ftinteger);
- FMinRange:=Low(LongInt);
- FMaxRange:=High(LongInt);
- FValidchars:=['+','-','0'..'9'];
- end;
- function TLongintField.GetAsFloat: Double;
- begin
- Result:=GetAsLongint;
- end;
- function TLongintField.GetAsLongint: Longint;
- begin
- If Not GetValue(Result) then
- Result:=0;
- end;
- function TLongintField.GetAsVariant: Variant;
- Var L : Longint;
- v : variant;
- begin
- If GetValue(L) then
- Result:=L
- else
- Result:=Null;
- end;
- function TLongintField.GetAsString: string;
- Var L : Longint;
- begin
- If GetValue(L) then
- Result:=IntTostr(L)
- else
- Result:='';
- end;
- function TLongintField.GetDataSize: Word;
- begin
- Result:=SizeOf(Longint);
- end;
- procedure TLongintField.GetText(var AText: string; ADisplayText: Boolean);
- var l : longint;
- fmt : string;
- begin
- Atext:='';
- If Not GetValue(l) then exit;
- If ADisplayText or (FEditFormat='') then
- fmt:=FDisplayFormat
- else
- fmt:=FEditFormat;
- If length(fmt)<>0 then
- AText:=FormatFloat(fmt,L)
- else
- Str(L,AText);
- end;
- function TLongintField.GetValue(var AValue: Longint): Boolean;
- Var L : Longint;
- P : PLongint;
- begin
- P:=@L;
- Result:=GetData(P);
- If Result then
- Case Datatype of
- ftInteger,ftautoinc : AValue:=Plongint(P)^;
- ftword : Avalue:=Pword(P)^;
- ftsmallint : AValue:=PSmallint(P)^;
- end;
- end;
- procedure TLongintField.SetAsFloat(AValue: Double);
- begin
- SetAsLongint(Round(Avalue));
- end;
- procedure TLongintField.SetAsLongint(AValue: Longint);
- begin
- If CheckRange(AValue) then
- SetData(@AValue)
- else
- RangeError(Avalue,FMinrange,FMaxRange);
- end;
- procedure TLongintField.SetAsVariant(AValue: Variant);
- begin
- SetAsLongint(AValue);
- end;
- procedure TLongintField.SetAsString(const AValue: string);
- Var L,Code : longint;
- begin
- If length(AValue)=0 then
- Clear
- else
- begin
- Val(AVAlue,L,Code);
- If Code=0 then
- SetAsLongint(L)
- else
- DatabaseErrorFMT(SNotAnInteger,[Avalue]);
- end;
- end;
- Function TLongintField.CheckRange(AValue : longint) : Boolean;
- begin
- result := true;
- if (FMaxValue=0) then
- begin
- if (AValue>FMaxRange) Then result := false;
- end
- else
- if AValue>FMaxValue then result := false;
- if (FMinValue=0) then
- begin
- if (AValue<FMinRange) Then result := false;
- end
- else
- if AValue<FMinValue then result := false;
- end;
- Procedure TLongintField.SetMaxValue (AValue : longint);
- begin
- If (AValue>=FMinRange) and (AValue<=FMaxRange) then
- FMaxValue:=AValue
- else
- RangeError(AValue,FMinRange,FMaxRange);
- end;
- Procedure TLongintField.SetMinValue (AValue : longint);
- begin
- If (AValue>=FMinRange) and (AValue<=FMaxRange) then
- FMinValue:=AValue
- else
- RangeError(AValue,FMinRange,FMaxRange);
- end;
- { ---------------------------------------------------------------------
- TLargeintField
- ---------------------------------------------------------------------}
- constructor TLargeintField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDatatype(ftLargeint);
- FMinRange:=Low(Largeint);
- FMaxRange:=High(Largeint);
- FValidchars:=['+','-','0'..'9'];
- end;
- function TLargeintField.GetAsFloat: Double;
- begin
- Result:=GetAsLargeint;
- end;
- function TLargeintField.GetAsLargeint: Largeint;
- begin
- If Not GetValue(Result) then
- Result:=0;
- end;
- function TLargeIntField.GetAsVariant: Variant;
- Var L : Largeint;
- begin
- If GetValue(L) then
- Result:=L
- else
- Result:=Null;
- end;
- function TLargeintField.GetAsLongint: Longint;
- begin
- Result:=GetAsLargeint;
- end;
- function TLargeintField.GetAsString: string;
- Var L : Largeint;
- begin
- If GetValue(L) then
- Result:=IntTostr(L)
- else
- Result:='';
- end;
- function TLargeintField.GetDataSize: Word;
- begin
- Result:=SizeOf(Largeint);
- end;
- procedure TLargeintField.GetText(var AText: string; ADisplayText: Boolean);
- var l : largeint;
- fmt : string;
- begin
- Atext:='';
- If Not GetValue(l) then exit;
- If ADisplayText or (FEditFormat='') then
- fmt:=FDisplayFormat
- else
- fmt:=FEditFormat;
- If length(fmt)<>0 then
- AText:=FormatFloat(fmt,L)
- else
- Str(L,AText);
- end;
- function TLargeintField.GetValue(var AValue: Largeint): Boolean;
- type
- PLargeint = ^Largeint;
- Var P : PLargeint;
- begin
- P:=@AValue;
- Result:=GetData(P);
- end;
- procedure TLargeintField.SetAsFloat(AValue: Double);
- begin
- SetAsLargeint(Round(Avalue));
- end;
- procedure TLargeintField.SetAsLargeint(AValue: Largeint);
- begin
- If CheckRange(AValue) then
- SetData(@AValue)
- else
- RangeError(Avalue,FMinrange,FMaxRange);
- end;
- procedure TLargeintField.SetAsLongint(AValue: Longint);
- begin
- SetAsLargeint(Avalue);
- end;
- procedure TLargeintField.SetAsString(const AValue: string);
- Var L : largeint;
- code : longint;
- begin
- If length(AValue)=0 then
- Clear
- else
- begin
- Val(AVAlue,L,Code);
- If Code=0 then
- SetAsLargeint(L)
- else
- DatabaseErrorFMT(SNotAnInteger,[Avalue]);
- end;
- end;
- Function TLargeintField.CheckRange(AValue : largeint) : Boolean;
- begin
- result := true;
- if (FMaxValue=0) then
- begin
- if (AValue>FMaxRange) Then result := false;
- end
- else
- if AValue>FMaxValue then result := false;
- if (FMinValue=0) then
- begin
- if (AValue<FMinRange) Then result := false;
- end
- else
- if AValue<FMinValue then result := false;
- end;
- Procedure TLargeintField.SetMaxValue (AValue : largeint);
- begin
- If (AValue>=FMinRange) and (AValue<=FMaxRange) then
- FMaxValue:=AValue
- else
- RangeError(AValue,FMinRange,FMaxRange);
- end;
- Procedure TLargeintField.SetMinValue (AValue : largeint);
- begin
- If (AValue>=FMinRange) and (AValue<=FMaxRange) then
- FMinValue:=AValue
- else
- RangeError(AValue,FMinRange,FMaxRange);
- end;
- { TSmallintField }
- function TSmallintField.GetDataSize: Word;
- begin
- Result:=SizeOf(SmallInt);
- end;
- constructor TSmallintField.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- SetDataType(ftSmallInt);
- FMinRange:=-32768;
- FMaxRange:=32767;
- end;
- { TWordField }
- function TWordField.GetDataSize: Word;
- begin
- Result:=SizeOf(Word);
- end;
- constructor TWordField.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- SetDataType(ftWord);
- FMinRange:=0;
- FMaxRange:=65535;
- FValidchars:=['+','0'..'9'];
- end;
- { TAutoIncField }
- constructor TAutoIncField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOWner);
- SetDataType(ftAutoInc);
- end;
- Procedure TAutoIncField.SetAsLongint(AValue : Longint);
- begin
- DataBaseError(SCantSetAutoIncfields);
- end;
- { TFloatField }
- function TFloatField.GetAsFloat: Double;
- begin
- If Not GetData(@Result) Then
- Result:=0.0;
- end;
- function TFloatField.GetAsVariant: Variant;
- Var f : Double;
- begin
- If GetData(@f) then
- Result := f
- else
- Result:=Null;
- end;
- function TFloatField.GetAsLongint: Longint;
- begin
- Result:=Round(GetAsFloat);
- end;
- function TFloatField.GetAsString: string;
- Var R : Double;
- begin
- If GetData(@R) then
- Result:=FloatToStr(R)
- else
- Result:='';
- end;
- function TFloatField.GetDataSize: Word;
- begin
- Result:=SizeOf(Double);
- end;
- procedure TFloatField.GetText(var TheText: string; ADisplayText: Boolean);
- Var
- fmt : string;
- E : Double;
- begin
- text:='';
- If Not GetData(@E) then exit;
- If ADisplayText or (Length(FEditFormat) = 0) Then
- Fmt:=FDisplayFormat
- else
- Fmt:=FEditFormat;
- If fmt<>'' then
- TheText:=FormatFloat(fmt,E)
- else
- TheText:=FloatToStrF(E,ffgeneral,FPrecision,0);
- end;
- procedure TFloatField.SetAsFloat(AValue: Double);
- begin
- If CheckRange(AValue) then
- SetData(@Avalue)
- else
- RangeError(AValue,FMinValue,FMaxValue);
- end;
- procedure TFloatField.SetAsLongint(AValue: Longint);
- begin
- SetAsFloat(Avalue);
- end;
- procedure TFloatField.SetAsString(const AValue: string);
- Var R : Double;
- Code : longint;
- begin
- Val(AVAlue,R,Code);
- If Code<>0 then
- DatabaseErrorFmt(SNotAFloat,[AVAlue])
- Else
- SetAsFloat(R);
- end;
- constructor TFloatField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDatatype(ftfloat);
- end;
- Function TFloatField.CheckRange(AValue : Double) : Boolean;
- begin
- If (FMinValue<>0) or (FmaxValue<>0) then
- Result:=(AValue>=FMinValue) and (AVAlue<=FMAxValue)
- else
- Result:=True;
- end;
- { TBooleanField }
- function TBooleanField.GetAsBoolean: Boolean;
- begin
- If not GetData(@Result) then
- Result:=False;
- end;
- function TBooleanField.GetAsVariant: Variant;
- Var b : boolean;
- begin
- If GetData(@b) then
- Result := b
- else
- Result:=Null;
- end;
- function TBooleanField.GetAsString: string;
- Var B : boolean;
- begin
- If Getdata(@B) then
- Result:=FDisplays[False,B]
- else
- result:='';
- end;
- function TBooleanField.GetDataSize: Word;
- begin
- Result:=SizeOf(Boolean);
- end;
- function TBooleanField.GetDefaultWidth: Longint;
- begin
- Result:=Length(FDisplays[false,false]);
- If Result<Length(FDisplays[false,True]) then
- Result:=Length(FDisplays[false,True]);
- end;
- procedure TBooleanField.SetAsBoolean(AValue: Boolean);
- begin
- SetData(@AValue);
- end;
- procedure TBooleanField.SetAsString(const AValue: string);
- Var Temp : string;
- begin
- Temp:=UpperCase(AValue);
- If Temp=FDisplays[True,True] Then
- SetAsBoolean(True)
- else If Temp=FDisplays[True,False] then
- SetAsBoolean(False)
- else
- DatabaseErrorFmt(SNotABoolean,[AValue]);
- end;
- constructor TBooleanField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDataType(ftBoolean);
- DisplayValues:='True;False';
- end;
- Procedure TBooleanField.SetDisplayValues(AValue : String);
- Var I : longint;
- begin
- If FDisplayValues<>AValue then
- begin
- I:=Pos(';',AValue);
- If (I<2) or (I=Length(AValue)) then
- DatabaseErrorFmt(SInvalidDisplayValues,[AValue]);
- FdisplayValues:=AValue;
- // Store display values and their uppercase equivalents;
- FDisplays[False,True]:=Copy(AValue,1,I-1);
- FDisplays[True,True]:=UpperCase(FDisplays[False,True]);
- FDisplays[False,False]:=Copy(AValue,I+1,Length(AValue)-i);
- FDisplays[True,False]:=UpperCase(FDisplays[False,False]);
- PropertyChanged(True);
- end;
- end;
- { TDateTimeField }
- function TDateTimeField.GetAsDateTime: TDateTime;
- begin
- If Not GetData(@Result) then
- Result:=0;
- end;
- function TDateTimeField.GetAsVariant: Variant;
- Var d : tDateTime;
- begin
- If Getdata(@d) then
- Result := d
- else
- Result:=Null;
- end;
- function TDateTimeField.GetAsFloat: Double;
- begin
- Result:=GetAsdateTime;
- end;
- function TDateTimeField.GetAsString: string;
- begin
- GetText(Result,False);
- end;
- function TDateTimeField.GetDataSize: Word;
- begin
- Result:=SizeOf(TDateTime);
- end;
- procedure TDateTimeField.GetText(var TheText: string; ADisplayText: Boolean);
- Var R : TDateTime;
- F : String;
- begin
- If Not Getdata(@R) then
- TheText:=''
- else
- begin
- If (ADisplayText) and (Length(FDisplayFormat)<>0) then
- F:=FDisplayFormat
- else
- Case DataType of
- ftTime : F:=ShortTimeFormat;
- ftDate : F:=ShortDateFormat;
- else
- F:='c'
- end;
- TheText:=FormatDateTime(F,R);
- end;
- end;
- procedure TDateTimeField.SetAsDateTime(AValue: TDateTime);
- begin
- SetData(@Avalue);
- end;
- procedure TDateTimeField.SetAsFloat(AValue: Double);
- begin
- SetAsDateTime(AValue);
- end;
- procedure TDateTimeField.SetAsString(const AValue: string);
- Var R : TDateTime;
- begin
- R:=StrToDateTime(AVAlue);
- SetData(@R);
- end;
- constructor TDateTimeField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDataType(ftDateTime);
- end;
- { TDateField }
- function TDateField.GetDataSize: Word;
- begin
- Result:=SizeOf(TDateTime);
- end;
- constructor TDateField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDataType(ftDate);
- end;
- { TTimeField }
- function TTimeField.GetDataSize: Word;
- begin
- Result:=SizeOf(TDateTime);
- end;
- constructor TTimeField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDataType(ftTime);
- end;
- { TBinaryField }
- class procedure TBinaryField.CheckTypeSize(AValue: Longint);
- begin
- // Just check for really invalid stuff; actual size is
- // dependent on the record...
- If AValue<1 then
- DatabaseErrorfmt(SInvalidFieldSize,[Avalue]);
- end;
- function TBinaryField.GetAsString: string;
- begin
- Setlength(Result,DataSize);
- GetData(Pointer(Result));
- end;
- procedure TBinaryField.GetText(var TheText: string; ADisplayText: Boolean);
- begin
- TheText:=GetAsString;
- end;
- procedure TBinaryField.SetAsString(const AValue: string);
- Var Buf : PChar;
- Allocated : Boolean;
- begin
- Allocated:=False;
- If Length(AVAlue)=DataSize then
- Buf:=PChar(Avalue)
- else
- begin
- GetMem(Buf,DataSize);
- Move(Pchar(Avalue)[0],Buf^,DataSize);
- Allocated:=True;
- end;
- SetData(Buf);
- If Allocated then
- FreeMem(Buf,DataSize);
- end;
- procedure TBinaryField.SetText(const AValue: string);
- begin
- SetAsString(Avalue);
- end;
- constructor TBinaryField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- end;
- { TBytesField }
- function TBytesField.GetDataSize: Word;
- begin
- Result:=Size;
- end;
- constructor TBytesField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDataType(ftBytes);
- Size:=16;
- end;
- { TVarBytesField }
- function TVarBytesField.GetDataSize: Word;
- begin
- Result:=Size+2;
- end;
- constructor TVarBytesField.Create(AOwner: TComponent);
- begin
- INherited Create(AOwner);
- SetDataType(ftvarbytes);
- Size:=16;
- end;
- { TBCDField }
- class procedure TBCDField.CheckTypeSize(AValue: Longint);
- begin
- If not (AValue in [1..4]) then
- DatabaseErrorfmt(SInvalidFieldSize,[Avalue]);
- end;
- function TBCDField.GetAsCurrency: Currency;
- Var C : system.Currency;
- begin
- if GetData(@C) then
- result := C;
- end;
- function TBCDField.GetAsVariant: Variant;
- Var c : system.Currency;
- begin
- If GetData(@c) then
- Result := c
- else
- Result:=Null;
- end;
- function TBCDField.GetAsFloat: Double;
- begin
- result := GetAsCurrency;
- end;
- function TBCDField.GetAsLongint: Longint;
- begin
- result := round(GetAsCurrency);
- end;
- function TBCDField.GetAsString: string;
- var c : system.currency;
- begin
- If GetData(@C) then
- Result:=CurrToStr(C)
- else
- Result:='';
- end;
- function TBCDField.GetDataSize: Word;
- begin
- result := sizeof(currency);
- end;
- function TBCDField.GetDefaultWidth: Longint;
- begin
- if precision > 0 then result := precision
- else result := 10;
- end;
- procedure TBCDField.GetText(var TheText: string; ADisplayText: Boolean);
- var c : system.currency;
- begin
- If GetData(@C) then
- begin
- if ADisplayText then
- begin
- if Displayformat='' then
- begin
- if Fcurrency then TheText := FloatToStrF(C,ffcurrency,FPrecision,0)
- else TheText := FloatToStrF(C,ffgeneral,FPrecision,0);
- end
- else
- TheText := CurrToStr(C); // ToDo: Displayformat is ignored
- end
- else
- begin
- if (Displayformat='') and (Editformat='') then
- begin
- if Fcurrency then TheText := FloatToStrF(C,ffcurrency,FPrecision,0)
- else TheText := FloatToStrF(C,ffFixed,FPrecision,0);
- end
- else
- TheText := CurrToStr(C); // ToDo: Displayformat is ignored
- end;
- end
- else
- TheText:='';
- end;
- procedure TBCDField.SetAsCurrency(AValue: Currency);
- begin
- If CheckRange(AValue) then
- setdata(@AValue)
- else
- RangeError(AValue,FMinValue,FMaxvalue);
- end;
- Function TBCDField.CheckRange(AValue : Currency) : Boolean;
- begin
- If (FMinValue<>0) or (FmaxValue<>0) then
- Result:=(AValue>=FMinValue) and (AVAlue<=FMaxValue)
- else
- Result:=True;
- end;
- procedure TBCDField.SetAsFloat(AValue: Double);
- begin
- SetAsCurrency(AValue);
- end;
- procedure TBCDField.SetAsLongint(AValue: Longint);
- begin
- SetAsCurrency(AValue);
- end;
- procedure TBCDField.SetAsString(const AValue: string);
- begin
- SetAsCurrency(strtocurr(AValue));
- end;
- constructor TBCDField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- FMaxvalue := 0;
- FMinvalue := 0;
- SetDataType(ftBCD);
- Size:=4;
- end;
- { TBlobField }
- procedure TBlobField.AssignTo(Dest: TPersistent);
- begin
- //!! To be implemented
- end;
- Function TBlobField.GetBlobStream(Mode : TBlobStreamMode) : TStream;
- begin
- Result:=FDataset.CreateBlobStream(Self,Mode);
- end;
- procedure TBlobField.FreeBuffers;
- begin
- end;
- function TBlobField.GetAsString: string;
- var
- Stream: TStream;
- begin
- Stream := GetBlobStream(bmRead);
- if Stream<>nil then
- With GetBlobStream(bmRead) do
- try
- SetLength(Result,Size);
- ReadBuffer(Pointer(Result)^,Size);
- finally
- Free
- end
- else
- Result := '(blob)';
- end;
- function TBlobField.GetBlobSize: Longint;
- var
- Stream: TStream;
- begin
- Stream := GetBlobStream(bmread);
- if Stream <> nil then
- With Stream do
- try
- Result:=Size;
- finally
- Free;
- end
- else
- result := 0;
- end;
- function TBlobField.GetIsNull: Boolean;
- begin
- If Not Modified then
- result:= inherited GetIsnull
- else
- With GetBlobStream(bmread) do
- try
- Result:=(Size=0);
- Finally
- Free;
- end;
- end;
- procedure TBlobField.GetText(var TheText: string; ADisplayText: Boolean);
- begin
- TheText:=GetAsString;
- end;
- procedure TBlobField.SetAsString(const AValue: string);
- begin
- With GetBlobStream(bmwrite) do
- try
- WriteBuffer(Pointer(Avalue)^,Length(Avalue));
- finally
- Free;
- end;
- end;
- procedure TBlobField.SetText(const AValue: string);
- begin
- SetAsString(AValue);
- end;
- constructor TBlobField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOWner);
- SetDataType(ftBlob);
- end;
- procedure TBlobField.Assign(Source: TPersistent);
- begin
- //!! To be implemented
- end;
- procedure TBlobField.Clear;
- begin
- GetBlobStream(bmWrite).free;
- end;
- class function TBlobField.IsBlob: Boolean;
- begin
- Result:=True;
- end;
- procedure TBlobField.LoadFromFile(const FileName: string);
- Var S : TFileStream;
- begin
- S:=TFileStream.Create(FileName,fmOpenRead);
- try
- LoadFromStream(S);
- finally
- S.Free;
- end;
- end;
- procedure TBlobField.LoadFromStream(Stream: TStream);
- begin
- With GetBlobStream(bmWrite) do
- Try
- CopyFrom(Stream,0);
- finally
- Free;
- end;
- end;
- procedure TBlobField.SaveToFile(const FileName: string);
- Var S : TFileStream;
- begin
- S:=TFileStream.Create(FileName,fmCreate);
- try
- SaveToStream(S);
- finally
- S.Free;
- end;
- end;
- procedure TBlobField.SaveToStream(Stream: TStream);
- Var S : TStream;
- begin
- S:=GetBlobStream(bmRead);
- Try
- Stream.CopyFrom(S,0);
- finally
- S.Free;
- end;
- end;
- procedure TBlobField.SetFieldType(AValue: TFieldType);
- begin
- If AValue in [Low(TBlobType)..High(TBlobType)] then
- SetDatatype(Avalue);
- end;
- { TMemoField }
- constructor TMemoField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDataType(ftMemo);
- end;
- { TGraphicField }
- constructor TGraphicField.Create(AOwner: TComponent);
- begin
- Inherited Create(AOwner);
- SetDataType(ftGraphic);
- end;
- { TFields }
- Constructor TFields.Create(ADataset : TDataset);
- begin
- FDataSet:=ADataset;
- FFieldList:=TList.Create;
- FValidFieldKinds:=[fkData..fkInternalcalc];
- end;
- Destructor TFields.Destroy;
- begin
- FFieldList.Free;
- end;
- Procedure Tfields.Changed;
- begin
- If Assigned(FOnChange) then
- FOnChange(Self);
- end;
- Procedure TFields.CheckfieldKind(Fieldkind : TFieldKind; Field : TField);
- begin
- If Not (FieldKind in ValidFieldKinds) Then
- DatabaseErrorFmt(SInvalidFieldKind,[Field.FieldName]);
- end;
- Function Tfields.GetCount : Longint;
- begin
- Result:=FFieldList.Count;
- end;
- Function TFields.GetField (Index : longint) : TField;
- begin
- Result:=Tfield(FFieldList[Index]);
- end;
- Procedure TFields.SetFieldIndex (Field : TField;Value : Integer);
- Var Old : Longint;
- begin
- Old := FFieldList.indexOf(Field);
- If Old=-1 then
- Exit;
- // Check value
- If Value<FFieldList.Count Then Value:=0;
- If Value>=Count then Value:=Count-1;
- If Value<>Old then
- begin
- FFieldList.Delete(Old);
- FFieldList.Insert(Value,Field);
- Field.PropertyChanged(True);
- Changed;
- end;
- end;
- Procedure TFields.Add(Field : TField);
- begin
- CheckFieldName(Field.FieldName);
- FFieldList.Add(Field);
- Field.FFields:=Self;
- Changed;
- end;
- Procedure TFields.CheckFieldName (Const Value : String);
- Var I : longint;
- S : String;
- begin
- If FindField(Value)<>Nil then
- begin
- S:=UpperCase(Value);
- For I:=0 To FFieldList.Count-1 do
- If S=UpperCase(TField(FFieldList[i]).FieldName) Then
- DataBaseErrorFmt(SDuplicateFieldName,[Value],FDataset);
- end;
- end;
- Procedure TFields.CheckFieldNames (Const Value : String);
- Var I : longint;
- S,T : String;
- begin
- T:=Value;
- Repeat
- I:=Pos(T,';');
- If I=0 Then I:=Length(T);
- S:=Copy(T,1,I-1);
- Delete(T,1,I);
- // Will raise an error if no such field...
- FieldByName(S);
- Until (T='');
- end;
- Procedure TFields.Clear;
- begin
- FFieldList.Clear;
- end;
- Function TFields.FindField (Const Value : String) : TField;
- Var S : String;
- I : longint;
- begin
- Result:=Nil;
- S:=UpperCase(Value);
- For I:=0 To FFieldList.Count-1 do
- If S=UpperCase(TField(FFieldList[i]).FieldName) Then
- Begin
- {$ifdef dsdebug}
- Writeln ('Found field ',Value);
- {$endif}
- Result:=TField(FFieldList[I]);
- Exit;
- end;
- end;
- Function TFields.FieldByName (Const Value : String) : TField;
- begin
- Result:=FindField(Value);
- If result=Nil then
- DatabaseErrorFmt(SFieldNotFound,[Value],FDataset);
- end;
- Function TFields.FieldByNumber(FieldNo : Integer) : TField;
- Var i : Longint;
- begin
- Result:=Nil;
- For I:=0 to FFieldList.Count-1 do
- If FieldNo=TField(FFieldList[I]).FieldNo then
- begin
- Result:=TField(FFieldList[i]);
- Exit;
- end;
- end;
- Procedure TFields.GetFieldNames (Values : TStrings);
- Var i : longint;
- begin
- Values.Clear;
- For I:=0 to FFieldList.Count-1 do
- Values.Add(Tfield(FFieldList[I]).FieldName);
- end;
- Function TFields.IndexOf(Field : TField) : Longint;
- Var i : longint;
- begin
- Result:=-1;
- For I:=0 To FFieldList.Count-1 do
- If Pointer(Field)=FFieldList[i] Then
- Exit(I);
- end;
- procedure TFields.Remove(Value : TField);
- Var I : longint;
- begin
- I:=IndexOf(Value);
- If I<>0 then
- FFieldList.Delete(I);
- end;
- {
- $Log$
- Revision 1.21 2005-01-12 10:29:54 michael
- * Patch from Joost Van der Sluis:
- - removed some duplicate definitions
- - restructured SetDataset
- - implemented UpdateMode, ProviderFlags
- Revision 1.20 2004/12/29 20:27:08 michael
- + Patch from Joost van der Sluis to correct AsVariant
- Revision 1.19 2004/12/13 19:20:42 michael
- * Patch from Joost van der Sluis
- - fixed bug #3180, TFields.Clear implemented
- - implemented TLargeintField
- Revision 1.18 2004/12/05 00:05:38 michael
- patch to enable RecNo and DisplayFormat
- Revision 1.17 2004/12/04 22:43:56 michael
- - implemented TBCDFields
- Revision 1.16 2004/11/30 21:18:34 michael
- + Fix from Jesus Reyes to fix TfieldDefs.Assign
- Revision 1.15 2004/08/21 21:10:00 michael
- * Patch from Joost van der Sluis
- - Empty recordsets don't show any bogus data anymore
- - Floatfiels.gettext fix
- - SetBufListsize fix forTDBGrid
- Revision 1.14 2004/08/01 13:00:29 michael
- + Patch for Tlongintfield by Joost van der Sluis
- Revision 1.13 2004/07/19 20:27:29 michael
- + Fixes from Jesus Reyes to implement DisplayWith, DisplayLabel, Visibility
- Revision 1.12 2004/07/18 13:16:50 michael
- + Changed extended to double for better Delphi compatibility
- Revision 1.11 2004/05/02 21:23:18 peter
- * use ptrint
- Revision 1.10 2004/03/25 20:43:39 michael
- Some compatibility additions
- Revision 1.9 2004/02/25 16:29:26 michael
- + Added AsInteger to TField. Maps to AsLongint for now
- Revision 1.8 2003/09/14 13:22:14 michael
- + Fixed error in TField.GetCanModify reported by Andrew Johnson
- Revision 1.7 2002/09/07 15:15:23 peter
- * old logs removed and tabs fixed
- }
|