[quote=kimmorleykiller;396222]Sorry guys,

Im using turbo pascal; and am using a text file to store data.

I uploaded the whole thing because its starting to get a little roomy, but here is a procedure im having trouble with:

[code]procedure addemployee;

begin
assign(EmployeeFile, 'C:\SDDBooks.txt');
reset(EmployeeFile);
Append(EmployeeFile);

  writeln('Please enter new employees identification number: ');
  readln(temp_id);
  writeln(EmployeeFile, temp_id);
  writeln;

  writeln('Please enter employees name: ');
  readln(newspaper[temp_id].employee);
  writeln(EmployeeFile, newspaper[temp_id].employee);
  writeln;

  clearfile;

[COLOR=red][/COLOR]
writeln('Are these details correct? [Y/N]');
readln(decision);

if (decision = 'y') or (decision = 'Y') then
begin
close(EmployeeFile);
end
else if (decision = 'n') OR (decision = 'N') then
begin
clearscreen;
welcome;
listoptions;
end
else
begin
writeln('Invalid input. Employee not saved.');
end

end;[/code]

This works but its got a lot of bugs in it, is there a way i can get the id number to automatically increase by one from the previous id number in the text file?[/quote]

You could either save your ID or determine the highest one used to date. Since you're using a text file, it could be saved by itself in the first line where you could find it easily. Be sure to write it back again at the end of the session.

As for the rest, it looks OK, but [I]clearFile[/I] seems to be something from your code. What does it do? Also, it looks like you are using an array named [I]newspaper [/I]and you're saving the employee name there indexed on the [I]temp_id.[/I] Is that correct? Why are you doing that?

Anyway, with all that in mind, I can ...

That is a little more encouraging. However, you didn't say if you got to the point that you could link data objects to your forms and reports at design time, and if you were able to create reusable classes or had to custom code each 'data module'. I'm sure that's all possible if I want to delve deeply enough into NET (though far more difficult since I don't have the code). For the moment, I will do what I need in code alone, I guess.

I am working with data for natural resources which involves lots of tables with lots of fields and lots of interrelations, so hand-coding everything is quite a chore. I'm finding that the amount of code required in C# is a LOT larger than Delphi. NET may well be more powerful than VCL, but I find it much harder to handle as well.

You didn't say what kind of Pascal you're using. You didn't tell us how you store your data (array, list, text file, database...). And we can't comment on wasted code without seeing any code. So, please give a few more details!

[quote=Killer_Typo;396057]i ran into an issue such as this a while back and ended up just writing a library to handle all SQL connections so that all forms had a central method for running their methods.[/quote]

I was afraid that might be the answer.

I've used Delphi for the past 12 years, but now I need to get up to speed in C#. Since both systems were designed by the same person, there are lots of similarities. However, C# seems to have a big gap when it comes to centralized data access. All of the examples I've seen show the connections, commands and datasets and so forth all being placed on individual forms with no interconnection.

The applications I work with have numerous primary and support tables with related queries and so on. If I have to redelcare these in every form where they are used, the code overhead will be huge and maintenance becomes a nightmare because I must make changes in multiple locations.

Delphi provides a container class called a 'data module' where connections and data access components can be installed during design. Data modules are also used to hold support code for events, business rules and so forth all in one place. Once defined, data aware controls in forms or other units can access those components as need be either during design or run time. This obviously reduces code and makes design and maintenace much easier.

I am assuming there is some way to do this, or at least achieve the same end, in .NET. However, I haven't come across an answer yet. Can anyone point me in the right direction? I don't want to do any serious work until I figure this problem out. Thanks.

[quote=JJarvis;391833]Head explodes But you can just make it so that the number will go through a loop too... and I still know that there should be a way to do it without IF statements...

Oh... and I've been trying programming for about a year... but I [B]am[/B] only 12...[/quote]

You only need the IF statement in this case if you want to keep all of the output as all letters. If that doesn't matter, sure, you can just run the loop directly and eliminate the first part of the IF in my example but letters at the end of the alphabet will end up as the characters which come after the letters in ASCII.

However, I still question why you are so interested in avoiding IF. It is one of the most important statements in any programming language, and something you will need to use in every program you ever write. When you think about it, even your loop is a form of an IF statement ("if we're not done, repeat this loop") If you try to find a way to write all of your programs without using IF you are going to have a very hard time of it.

Are you perhaps confusing IF with GOTO? That statement (which isn't even available in some languages) is indeed considered bad programming and is best avoided except in special circumstances.

Anyway, good luck, hope this helps a little.

You are on the right track, and yes you need a loop. However, whoever told you that using IF was lazy programming has no idea what they are talking about! Conditional execution is one of the cornerstones of programming. Example: what happens if you enter Y or Z? You go beyond the end of the ASCII uppercase alphabet. My idea is to cycle back to the start in that case so that ABCXYZ becomes CDEZAB and so on, and that requires use of IF.

Anyway, all you need is a loop to iterate over the characters in a string, convert them and put them back (looks like you need to read up on string use too)

[CODE]
procedure Convert(var s :string);
var
i :integer;
begin
for i := 1 to Length(s) do
if Ord(s[i]) >= Ord('Y') then
s[i] := Chr(Ord(s[i])-24)
else
s[i] := Chr(Ord(s[i])+2);
end;

[/CODE]

Also note that you can use the result of Ord and Chr without storing them in intermediate variables.

You need to set the Form's [B]KeyPreview[/B] property to True before you can capture keyboard events.

I've never used MySQL, but since your structure is the same in all cases, it makes ssnse to put everything into one big database with a key to indicate which user each record belongs to. That will probably save you a lot of trouble in the long run. For instance, if you need to change the structure later, it will be a lot easier to change in once instead of 400 times. The only question is if MySQL can handle that number of records without a problem.

I forgot to point out in my last post that X is the number for which we need the square root and R is the initial guess. About anything can be used for R but a good guess will result in fewer loops than a bad one.

I just had to solve this, so I Googled it and found the answer a few seconds. No logs or any high math is required. And yes, it is true that it will not find the EXACT answer for a lot of numbers, but there are two reasons for that: First many numbers do not have an exact square root (kind of like Pi). Second, we are dealing with binary data which limits the accuracy for a lot of things (ever hear of round off error?). Anyway, here is the calculation. Sorry, it is in Pascal. I quit using C++ 10 years ago. It shouldn't be a problem to convert.

function SquareRoot(x, r: double): double;
var
last :double;
begin
last := 0;
repeat
last := r;
r := (r + (x/r))/2;
until (r = x/r) or (r = last);
result := r;
end;

Note the need for the variable [B]last. [/B]That is necessary due to the possible error mentioned above. The final result may not be exact, but once the program cannot get any closer due to the imprecision of double and/or numbers with no exact square root, it will come up with the same approximation every time, so to avoid and endless loop, you must exit.

OK, now that everyone has had a good joke about this - I had to do this years ago using a very primitive BASIC. I can't remember the exact algorithm, but I reasoned that guys like Sir Isaac Newton and his crowd didn't have calculators or even log tables and they did some pretty hairy calculations. So...I looked up the topic in some really old books to see how it was done before we had computers.

The trick is to make a guess, determine your error and then make a new guess based on your error. You may also have to specify a required accuracy range (since you can't get perfect for many numbers using binary math). You make a loop which continually refines your guess based on your last error and exit when the guess is within your required accuracy range. I remember that the code was only a few lines of BASIC and it only needed to loop a few times for even very large numbers.

Anyway, if no one gives you a straight answer by tomorrow I will try to remember just how it went and post here again, but that should be enough for you to figure it out.

Cheers.

[quote=Thon;375403]Windows was originally an application written in Pascal that ran on top of DOS. Pascal was popular in the eighties because it embodied the principles of structured programming. It was a very restrictive language since it was intended to channel the programmer into good programming practice and forbid the bad. It was a real nanny language. Very frustrating. It was overtaken by C which gave the programmer greater freedom especially with hardware.[/quote]

I never heard about the Pascal link to Windows before. Where did you hear that? As for Pascal being a 'nanny' language, why did Borland write their C compiler in Delphi? Yeah, Pascal used to be a little nerdy, but that was 20 years ago. I'm not aware of anything important that C can do and modern Pascal cannot. On the other hand, Pascal is a LOT easier to debug and maintain thanks to all of those arcane rules. Like a friend of mine once said - there are least 10 ways to do anything in C. 9 of them are a bad idea and the 10th one will really screw you. Amen.

It is correct that The Bill didn't write DOS - see [URL]http://inventors.about.com/library/weekly/aa033099.htm[/URL] for a quick history. Also note that the Altair BASIC was also used on the TRS-80, which sold a lot more units than Altair. Windows is indeed C and assembler, with C++ in the later versions. As for NET - it is mostly just a shell over Windows COM technology. COM is still being supported and upgraded by Microsoft, which makes me wonder if NET will ever become a 'real' OS, even in Redmond.

Here is another thing which might be of use. I have seen instances where a program jumps to unexpected code as it is shutting down. For instance, Delphi may the OnActivate event of an open form even when the program is terminating. Apparently, the form needs to become active before it can be closed. There is an easy way to block that kind of behavior - before the first line of the problem code include the line
[B] if Application.Terminated then EXIT;
[/B]That will prevent the rest of the code from executing. Not an elegant solution, perhaps, but it helps.
Good luck

  1. what age they started programming.
    About 30, but then again that was 30 years ago when the first Radio Shack TRS-80 became available. It used "Level I BASIC" (by Bill Gates and Paul Allen - too bad we didn't stop them then).

  2. how did they learn the language of their choice.
    My first language "of choice" was Forth (still one of the most powerful I ever used). I used it because it was small enough to fit on the Trash-80 and far faster than BASIC. When I went to PCs I tried about everything (C, C++, Java, Smalltalk, "4GL" systems...). Most of my work has been in Pascal, Modula-II and Delphi because they are the easiest to debug and maintain in the long run and every bit as powerful as those from the C family.

  3. which one is their favourite now.
    Delphi. For Win32 it cannot be beat. For NET I'd probably go with C# (designed by the same guy who did Delphi). VB prior to NET was a good idea which never got finished. The NET version is a lot better but from what I hear not many people are using it.

  4. can parents/schools help kids learn programming at an early age to get them started into [URL="

I'm an experience Windows programmer and I'd like to do some work for my wife's school on Mac OSX. The trouble is, I have found no decent programming tools for that system. When I work on Windows I use Delphi or Visual Studio. Does a visual, objected oriented RAD system exist for Mac or not? While I'm at it, what is a good database (local or LAN) for that system?

When I've asked people at Mac stores these questions, they look at me like no one ever asked before. Somebody must know how to program these things. Or, so I hope.

It looks like what you really want to do is copy a file from one place to another. In this case you want to copy it from a web location, I think. Look in Delphi Help for the [B]CopyFrom[/B] procedure. That will copy a file from one place to another on a single computer. I'm not sure whether it will work when the source is on the web, but it might if you specify the web address in the source parameter. You might want to start a new thread to ask how to use Delphi to copy a file from a web application to your computer.

I assume you are using a TTable or TQuery to handle your dBASE file. In both cases, those classes are descendents of TDataSet. The Delphi Help system states the following concering the Insert and InsertRecord methods:
[I]For dBASE, FoxPro, and Access tables, the record is physically appended to the dataset at the end. If an index happens to be active, the new record may appear in a position relative to the index, but the record is still actually stored at the end of the table.[/I]
Sorry, but you need to use an index and do a little programming to keep the index current.

A Zip file has nothing to do with Delphi (the programming system, anyway). In most cases, you can just run the Zip file at download and it will unzip its contents on your computer. In some cases, you need a program such as WinZip to unpack the file but most zip files can unpack themselves.

The problem is that you are referring to the TYPE TSam1 when you call your method. That is only possible if the method is a class method (and if you're a new student, you won't have heard about class methods yet). What you need to do is declare a variable of the type TSam1, create an instance of that type and assign it to the variable and then use the variable to call your method:

var
mySam :TSam1
begin
mySam := TSam1.Create;
mySam.DisplayResult;
end;

PS- why are you declaring TSam1 at all? The way your code reads, it is exactly the same as SampleClass and is unnecessary. Maybe you were attempting to create an instance of SampleClass named TSam1, in which case your syntax was incorrect.

As long as you're at it, here is how you get the program to run your Prime method when the Enter key is pressed without including a button:

  1. Set the [B]KeyPreview[/B] property of your form to True.
  2. Go to the Events page of the form and double-click in the empty space to the right of the [B]OnKeyDown[/B] event. This will create an empty method for this event.
  3. In the event Delphi generates, add this code:
    [COLOR=green]if Ord(Key) = VK_Return then (call your Prime function here)[/COLOR]
    Note that VK_Return is a constant defined as an integer, so you need to cast the Key value passed to your method before you can compare it to the character which you typed.

PS-They still teach Delphi in (good) schools because it is one of the best development tools for Windows and not too bad for Web and NET apps too.

You state that valid scores are 0 through 20 and the number of scores is unknown, so your condition is correct. You need to do the loop until an invalid score (say -1) is entered. Within the loop, you need to add the score to a tally variable and incriment a second count variable. When you exit the loop, divide the sum of the scores by the number of scores to get your average. While most Pascal systems will set the initial value of your variables to zero, it is always a good idea to do so in code anyway before you enter the loop.

You need a global variable which maintains the highest score seen so far which is updated in your While loop. Be sure to preset it to zero. You could also add additional global variables to save the name when a new high score was encountered

[COLOR=#444444][B]Global variable highscore, HighName[/B][/COLOR]
[COLOR=#444444][B]Highscore = 0[/B][/COLOR]
[COLOR=#444444][B]HighName = ''[/B][/COLOR]
[COLOR=#444444] [/COLOR]
[COLOR=#444444]1. NameßGetName()

  1. While(name <>”done”)do
  2. Call GetRest(age, goal, assists, league_factor)
  3. eval_figureß CalcEvaluation(page,pgoals,passists,pleague_factor)[/COLOR]
    [COLOR=#444444][B] if eval_figure > highscore then [/B][/COLOR]
    [COLOR=#444444][B] highscore = eval_figure[/B][/COLOR]
    [COLOR=#444444][B] HighName = Name[/B][/COLOR]
    [COLOR=#444444][B] endif
    [/B]5. DispDetail(name, age, goal, assists, league_factor, eval_figure)
  4. Nameß GetName()
    Endwhile[/COLOR]
    [COLOR=#444444] [/COLOR]
    [COLOR=#444444][B]print(Highname, Highscore)[/B][/COLOR]

Hi,
My name is Terry. A bit older than average (60 - but my wife was born the same month I graduated high school, so she says that takes off 10 years). I've been programming since '79, used BASIC, Assembler, Forth, dBASE, Paradox, Clarion, Turbo Pascal, C, Modula-2, C++, Delphi and C# (roughly in that order). I use Delphi for all serioius work, as I find NET to be a bit of a hack, although unfortunately it cannot be ignored.

I run a fish hatchery in Colorado and develop applications (mainly database and math) for the Colorado Division of Wildlife. I plan to get out of the fish business and into consulting later this summer. Standing in ice water all day helping fish have sex isn't all it's cracked up to be.

When I'm not working, I'm usually skiing (Crested Butte, Monarch, Telluride), biking, motorcycling or playing with the dogs or my child bride.

I found this site while searching for a solution to a problem we're having with one of our big data systems. I didn't find any answers yet, but you folks look interesting!

I have an Access 2002 managed replica set running on about 80 sites which communitcate via Indirect Synchronization with a hub replica on a server in a State Government network. Some users are connected directly, some are on DSL and some of us are on satellite or even dialup. All are using VPN security.

The problem is that computers which have been had GIS mapping software installed report "Invalid http address" when synchroniztion is attempted. However, the server involved is visible to those machines. In the past few weeks, new laptops running WinXP have also showed the same problem, even when GIS is not installed. I suspect a DLL change in MDAC or Windows. My app is written in Delphi 7, communication is via ADO. However, the synchronization problem happens whether synchronization is called from the Delphi app or the Access UI, which makes it appear likely the OS or its utilities are at fault Has anyone else ever seen this or know the cause?

You didn't say what Pascal you are using, but typically readln expects a text variable and you are passing an integer. If the point is to read in an ASCII code and then print out the character, you need to read in the text, convert it to an integer and then convert the integer to the character.