Board index » delphi » Delete

Delete

Quote
> can anyone help me more than the pascal help files in regards to delete.
> I need to delete a record from an array i.e
> procedure Delete(var prints : table; var client : name);
> var target : string[10];
>     found : boolean;
>     count, b : integer;
> begin
>   writeln('Enter client name');
>   readln(target);
>   found := false;
>   count := 0;
>   repeat
>      count := count + 1;  found := target = client[count]
>   until found or (count = 10);
>   if found then
>     begin
>        writeln('name...',client[count]);
>       Delete(client[count])

   First, "Delete" is a standard identifier in TP/BP (it's a string
procedure), and although you're allowed to override it, using it with
your own definition prevents you from using the normal one.  It's usually
a poor idea to redefine a standard name...
   Second, you have, by using this code, declared Delete as a _recursive_
procedure, and I really doubt that was your intent.  Because I don't
think you wanted to do this, I wonder what you intended this call to do.  
As it exists here, it will make a (recursive) call to itself (and not
accomplish anything), and I'm quite sure the program will eventually
abort with a 202 Stack Overflow...or perhaps lock up with an infinite
loop.  Either way, I'm pretty sure you don't want that...

Quote
>     end
>   else
>     writeln('Name not found');
> end;

   As you describe the problem, I once you find a match, you only want to
move array element(s) which are "to the right" of the element to be
deleted one array position to the left.  Then, you want to set some sort
of "sentinel" in the last array element (to signify a "null record"), or
you want to reduce the array size index by one.  
   However, this simple process has difficulties: if the matching element
is the last in the array, no move is required.  It also implies that you
maintain a separate "array size" value, so that you know how many
elements are present in the array.
   You can also "logically delete" any given record - by declaring a
"present flag" variable in each record and using it (true or false) to
define whether the record exists or not.  That means that the record
isn't physically removed from the array, but that deleted (marked as not
present) are ignored in processing after the flag variable is set.
   There are several other ways of dealing with this "delete" problem,
but I suspect this is a school assignment and that the above is enough to
get you going.
 

Re:Delete


Quote
> >   First, "Delete" is a standard identifier in TP/BP (it's a string
> >procedure), and although you're allowed to override it, using it with
> >your own definition prevents you from using the normal one.

> That is not true. You can always write system.delete()

   Certainly.  But he didn't do that, and he clearly didn't understand
the basic concept that might have "bitten" him.

Re:Delete


can anyone help me more than the pascal help files in regards to delete.
I need to delete a record from an array

i.e
procedure Delete(var prints : table; var client : name);
var target : string[10];
    found : boolean;
    count, b : integer;
begin
  writeln('Enter client name');
  readln(target);
  found := false;
  count := 0;
  repeat
     count := count + 1;
     found := target = client[count];
  until found or (count = 10);
  if found then
    begin
       writeln('name...',client[count]);
      Delete(client[count]);
    end
  else
    writeln('Name not found');
end;

Re:Delete


In article <MPG.135d31a7b5dab8e3989...@news.primenet.com>,

Quote
Mike Copeland <mrc...@primenet.com> wrote:
>   First, "Delete" is a standard identifier in TP/BP (it's a string
>procedure), and although you're allowed to override it, using it with
>your own definition prevents you from using the normal one.

That is not true. You can always write system.delete()

Osmo

Other Threads