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?
LVL 1
DonBartholomewAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheNeilCommented:
No idea why it doesn't work but why not use a temporary TDateTime variable? Assign the value from the table into that and then assign that into your datetimepicker

The Neil
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DonBartholomewAuthor Commented:
Sure, but is there no way to do it directly ?
0
DonBartholomewAuthor Commented:
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.
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

kretzschmarCommented:
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

0
kretzschmarCommented:
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

0
kretzschmarCommented:
oops already accepted :-(
0
TheNeilCommented:
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
0
kretzschmarCommented:
doesn't matter, the neil ;-)
0
DonBartholomewAuthor Commented:
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.
0
TheNeilCommented:
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
0
DonBartholomewAuthor Commented:
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?
0
TheNeilCommented:
UK - So it's about 11am here (and hey, this certainly beats doing some work). You?

The Neil
0
DonBartholomewAuthor Commented:
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?
0
DonBartholomewAuthor Commented:
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
0
TheNeilCommented:
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
0
DonBartholomewAuthor Commented:
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?
0
TheNeilCommented:
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
0
DonBartholomewAuthor Commented:
No problemo. See ya, I'm off to the drink. Bartman.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.