Link to home
Start Free TrialLog in
Avatar of DonBartholomew
DonBartholomew

asked on

Initializing datetimepickers

Every time I try to set a datetimepicker to a date from a database field, I get an access violation. Line: dtpDate.Date := dtmAdmin.ADOqryHolidays.Fields.FieldbyName('Date').AsDateTime. This does not work. Why?
ASKER CERTIFIED SOLUTION
Avatar of TheNeil
TheNeil

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DonBartholomew
DonBartholomew

ASKER

Sure, but is there no way to do it directly ?
That option did cross my mind, but I always wonder WHY. I'll accept it for an answer though, 'cause it works. I'll have to accept some facts in life: if you can't go straight, take a detour.
Avatar of kretzschmar
hi DonBartholomew,

i guess, if the field is Null you get this error, therefore test before like

if not(dtmAdmin.ADOqryHolidays.Fields.FieldbyName('Date').IsEmpty) then
dtpDate.Date := dtmAdmin.ADOqryHolidays.Fields.FieldbyName('Date').AsDateTime

meikl

hi DonBartholomew,

i guess, if the field is Null you get this error, therefore test before like

if not(dtmAdmin.ADOqryHolidays.Fields.FieldbyName('Date').IsEmpty) then
dtpDate.Date := dtmAdmin.ADOqryHolidays.Fields.FieldbyName('Date').AsDateTime

meikl

oops already accepted :-(
Sorry kretzschmar. If I could give you then points then I would.

I do agree with your suggestion of the field being empty though

The Neil
doesn't matter, the neil ;-)
Well, all my input is achieved through a SQL7 insert stored procedure, in which I check if required fields are not null, and if they are valid dates, so I'm working on an error-free table.
But maybe it's the interacting between the data module and the form unit that causes the access violation.
Could it be that you're trying to assign data directly from the database to a visual component? I know that's a stupid suggestion and I wouldn't normally make it but it could be the sort of bizarre thing crops up now and then.

Being flippant I'd say that you have a solution so just go with it, but as to WHY the assign won't work directly then I'm fresh out of ideas. Maybe it is something to do with the interaction between the database and the form...

The Neil
Nono, I just write stored procedures for datasets/commands. We manage most transactions server-side, cause it cuts transaction time. Delphi inputs are ready-to-use datasets. But you're right, I got away with it, that should be enough. See ya the next question.
What time zone u in? Do u never sleep?
UK - So it's about 11am here (and hey, this certainly beats doing some work). You?

The Neil
Nono, I just write stored procedures for datasets/commands. We manage most transactions server-side, cause it cuts transaction time. Delphi inputs are ready-to-use datasets. But you're right, I got away with it, that should be enough. See ya the next question.
What time zone u in? Do u never sleep?
Sorry, went offline and the thing had to reconnect- it sent the info again. This is chatting in an odd place, but who cares. I'm in Brussels, 12:34 here. Currently working on a project for automated administration. Holiday requests must be passed electronically and so on. This is because the company's staff is scattered all over the country, including some home-workers. It's new year's champagne reception in a few hours, so I'm slowing down already. Bartman
New Years?!?!?!?! Last time I checked the date it was January the 10th-It's alright for some. Does that Champagne conform to all the European regulations regarding the consumption of everything? (Sorry, unsubtle stab at European Union).
I'm bored out of my tiny skull at the moment so I'll carry on this chat. Supposed to be doing some error/event logging system using MTS, ADO, and COM objects but stuck waiting for other people to finish their bits off.

The Neil
Well, right now I'm preventing people from doing errors. My boss here even asked me if a could write a component to replace a db navigation bar, cause it's not foolproof enough! I'm thinking of integrating a dbgrid with a toolbar into one component, with some self-explanatory buttons in it, and en/disabling scrolling/modifying when appropriate to help idiot users. Got any tips?
Databases aren't really my strong point and I haven't had much experience when it comes to component creation (my code tends not to get reused much) but dealing with idiot users IS something that I know about. Just make sure that everything is blatantly clear as to what it does, build in loads of "Are you sure that you want to do this?" messages and that sort of thing. Of course having everything in one component makes keeping an eye on the user a lot simpler but can't help you on this one I'm afraid.

The Neil
No problemo. See ya, I'm off to the drink. Bartman.