[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Changin default value of a paradox field

Posted on 2002-05-27
14
Medium Priority
?
370 Views
Last Modified: 2010-04-04
Hi All,

I've created one field which has a default value 100 (this default value is assigned using database desktop utility), I want to have a delphi piece of code using which I can change the default value of any database field to any user defined value.

Thanks in advance

Rammohan
0
Comment
Question by:splram
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 4
14 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7036998
have one piece . . . searching
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7037013
here it comes,

bde-unit is used in the unit-clause

from my paqs, modified dbiapi-samples

---------- Validation

For setting a validation-check in paradox

//Set a Valcheck, valcheck may not exist
procedure SetValCheck(Tbl: TTable; Field: TField; MinVal, MaxVal,
          DefVal: Pointer; MinSize,MaxSize,DefSize : Integer; Required: Bool);
var
 hDb: hDbiDb;
 TblDesc: CRTblDesc;
 VChk: pVChkDesc;
 Dir: String;
 NumVChks: Word;
 OpType: CROpType;

begin
 NumVChks := 0;
 SetLength(Dir, dbiMaxNameLen + 1);
 Check(DbiGetDirectory(Tbl.DBHandle, False, PChar(Dir)));
 SetLength(Dir, StrLen(PChar(Dir)));
 VChk := AllocMem(sizeof(VChkDesc));
 try
   FillChar(TblDesc, sizeof(CRTblDesc), #0);

   VChk.iFldNum := Field.Index + 1;
   Tbl.DisableControls;
   Tbl.Close;
   Check(DbiOpenDatabase(nil, nil, dbiReadWrite, dbiOpenExcl,
              nil, 0, nil, nil, hDb));
   Check(DbiSetDirectory(hDb, PChar(Dir)));
   with VChk^ do
   begin
     bRequired := Required;
     if MinVal <> nil then
     begin
       Inc(NumVChks);
       bHasMinVal := True;
       move(MinVal^, aMinVal, MinSize);
     end
     else
       bHasMinVal := False;
     if MaxVal <> nil then

     begin
       Inc(NumVChks);
       bHasMaxVal := True;
       move(MaxVal^, aMaxVal, MaxSize);
     end
     else
       bHasMaxVal := False;
     if DefVal <> nil then
     begin
       Inc(NumVChks);
       bHasDefVal := True;
       move(DefVal^, aDefVal, DefSize);
     end
     else
       bHasDefVal := False;

   end;
   TblDesc.iValChkCount := NumVChks;
   TblDesc.pVChkDesc := VChk;
   OpType := crADD;
   TblDesc.pecrValChkOp := @OpType;

   StrPCopy(TblDesc.szTblName, Tbl.TableName);
   StrCopy(TblDesc.szTblType, szParadox);
   Check(DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil, False));
 finally
   Check(DbiCloseDatabase(hDb));
   FreeMem(VChk, sizeof(VChkDesc));
   Tbl.EnableControls;
   Tbl.Open;
 end;
end;

//Help Function to encode bde-date
Function GetBDEDate(Month, Day : Word; Year : SmallInt; var MyDate : DbiDate) : DbiDate;
begin
 Check(DbiDateEncode(Month, Day, Year, MyDate));
 Result := Mydate;
end;


//Table must be opened exclusive,
//a validate check may not exist
procedure TForm1.Button2Click(Sender: TObject);
var
 cmin,cmax,cdef : Double;
 lmin,lmax,ldef : Longint;
 amin,amax,adef : String;
 bdef : Boolean;
 dmin,dmax,ddef : dbiDate;
begin
 //Set validate for numeric Field
 cmin := -2.5;
 cmax := 2.5;
 cdef := 0.01;
 SetValCheck(Table6,Table6.FieldByName('Numeric'),@cmin,@cmax,@cdef,
             SizeOf(cMin),SizeOf(cMax),SizeOf(cdef),True);

 //Set Validate for Integer Field
 lmin := -100;
 lmax := 100;
 ldef := 1;
 SetValCheck(Table6,Table6.FieldByName('Integer'),@lmin,@lmax,@ldef,
             SizeOf(lMin),SizeOf(lMax),SizeOf(ldef),True);

 //Set Validate for Alphanumeric Field
 amin := 'A';
 amax := 'ABCDE';
 adef := 'AB';
 SetValCheck(Table6,Table6.FieldByName('Alpha'),@amin[1],@amax[1],@adef[1],
             length(amin),length(aMax),length(adef),True);

 //Set Validate for Boolean Field (Default only)
 bdef := False;
 SetValCheck(Table6,Table6.FieldByName('Boolean'),Nil,nil,@bdef,
             0,0,SizeOf(bdef),True);

 //Set Validate for DateField
 dMin := GetBDEDate(1,1,1999,dmin);
 dMax := GetBDEDate(12,31,1999,dmax);
 dDef := GetBDEDate(7,1,1999,ddef);
 SetValCheck(Table6,Table6.FieldByName('Date'),@dmin,@dmax,@ddef,
             SizeOf(dMin),SizeOf(dMax),SizeOf(ddef),True);
end;


-- hope this helps

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7037019
appendix

if you want only set defaults,
them set the min and max-value to nil
like in the boolean sample above

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:splram
ID: 7037041
Thanks for your prompt/early reply, I'm getting an error message when trying to change the default value for a string field the error is:

"INVALID ARRAY OF VALIDITY CHECK DESCRIPTORS".

This is how I'm invoking the SetValCheckFunction

amin := 'A';
amax := 'ABCDE';
adef := 'AB';
SetValCheck(Table1,Table1.FieldByName('Funcloc'),nil,nil,@adef[1],
            0,0,length(adef),True);


Whats wrong with this?

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7037062
which delphi-version do you use?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7037081
just to say the sample was for d3 long time ago,

it could be that in later versions this conversion
,@adef[1], did not work.

replace it with

PChar(adef)

well, testing myself this evening (with d5)
(no delphi on hand yet)

meikl ;-)

           
0
 

Author Comment

by:splram
ID: 7037089
Though I changed it to pchar(adef) its giving the same error, FYI, I'm working with delphi 5

the statement where error is cropping is:

  Check(DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil, False));
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7037094
well,
checking myself this evening (d5 i can check :-)
thats in ~5 hours

meikl ;-)
0
 

Author Comment

by:splram
ID: 7037103
I think you have taken Me to the 1 step behind the solution, I would owe My sincere thanks if you can take Me to the complete solution.

Thanks a lot for your contrinution, hope I get answer after 5 hrs.

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7037107
i will do my best for reproducing and solving
we will see, what happened :-))
0
 

Author Comment

by:splram
ID: 7037155
Hello meikl,

Kudos to you, I cracked the error the problem was:

OpType was crAdd,
I changed it to
crMODIFY;

Then worked thanks a ton

bye
Rammohan
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 800 total points
ID: 7037164
ahh,

thats, why i wrote
//a validate check may not exist
:-))

but its now about ~3 years ago,
i wrote this based on a bdeapi-sample from borland,
and i guess i had searched some time
to get the cause on the opType for your reported failure

well glad you got it work

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7037201
ahh,

thats, why i wrote
//a validate check may not exist
:-))

but its now about ~3 years ago,
i wrote this based on a bdeapi-sample from borland,
and i guess i had searched some time
to get the cause on the opType for your reported failure

well glad you got it work

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7037203
oops, doublepost, sorry :-))
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question