With computers and machinery always becoming more complex and more powerful, it is not far-fetched to assume that they may become self-aware and maybe sentient, which would require to give them a status of lifeforms. But where do we have to draw a line? Where does Star Trek draw the line?
TOS Although androids showed up as early as in the first season (TOS: "What are Little Girls Made of?"), Star Trek needed some time to discover the storytelling potential of a debate whether an android or another artificial intelligence should be acknowledged as a lifeform or not. Androids, robots and computers in TOS were commonly just regarded as machines, although they were said to be highly advanced on many occasions. No one truly posed the question whether they should be classified as sentient or ultimately as lifeforms. The word "sentient" was hardly ever spoken out up during TOS anyway. While strange but supposedly "natural" lifeforms were hunted down relentlessly more than once, there are several other occasions in which they were saved in the spirit of "exploring strange new life". A machine, on the other hand, was at most conceded the attribute of being intelligent. Although there was never a hint that androids existed in the Federation or in Starfleet, the impression is that anyone like Data would have been denied their rights of individuality in the 23rd century. Even more drastically, alien androids and machines were routinely destroyed or "discussed to death", like it happened in TOS: "Return of the Archons", "A Taste of Armageddon", "The Changeling" or "The Apple". No one really felt sorry about them. On the contrary, their obvious intelligence was rated as dangerous for humanity. Much like with genetically enhanced humans, there was something eerie and intrinsically villainous about autonomous androids. They were either programmed to be "evil" or they ran out of control because of accidents, giving themselves the goal to rule over biological lifeforms or to exterminate them like in TOS: "What are Little Girls Made of?" or "I, Mudd". Although they did not have humanoid shapes, we can easily include Landru, the Planet Killer (TOS: "The Doomsday Machine"), Nomad (and its clone M-5 from TOS: "Requiem for Methuselah"), Daystrom's M-5 and several more artificial intelligences to this category.
Only Rayna, the female android in TOS: "Requiem for Methuselah", marks a notable exception. She was the first artificial lifeform in Star Trek to clearly exhibit not only sentience but obviously feelings too. And it was the first time that this was acknowledged by the ship's crew, especially considering that Kirk fell in love with her. Rayna eventually "died" when she could not cope with her conflicting feelings (for Kirk and for Flint). While this outcome is still reminiscent of the computers that Kirk argued to death because they couldn't process contradictory commands or information, Rayna's tragic end also bears traits of more or less illogical self-destructive tendencies of humans, of the kind that machines are just not supposed to exhibit. But Rayna's existence probably remained isolated anyway, because Flint died soon afterwards and may not have built other androids of her kind. Another example of an artificial lifeform that is shown in a positive light is V'ger from "Star Trek: The Motion Picture", even though V'ger destroys anything in its flight path (apparently not knowing what killing a lifeform actually means in an ethical sense). In any case V'ger's quest for its creator is one more characteristic that is typical of lifeforms, not of machines.
TNG and beyond The turning point in the question of the rights of artificial lifeforms was Data. It was obvious from the first episode that he was assumed to be intelligent and probably sentient, although he himself had to admit that he was unable to experience emotions. He usually missed the point of fundamental human(oid) feelings and also of humor, like in his fruitless efforts to be funny (TNG: "Unnatural Selection"). Still, he was a fully privileged graduate of Starfleet Academy, not an honorary Lt. Commander, as Riker suspected in TNG: "Encounter at Farpoint". Data must have been admitted to Starfleet Academy like any other cadet, and this would necessarily require that he was acknowledged as a sentient being already back then -- unless Starfleet would want an army of mindless robots instead of (self-)responsible officers. In this light it is odd why in TNG: "The Measure of a Man" Commander Maddox could simply demand Data to be disassembled because, as he claimed, Data was Starfleet's property. Essentially the same question showed up when Admiral Haftel demanded Lal's extradition with much the same arguments in TNG: "The Offspring". On a side note, even if Data was not regarded as a person but as a thing, how could Starfleet claim ownership on him, when he legally belonged to Dr. Noonien Soong? It is only possible that some later jurisdiction may have been used to override Data's entry into Starfleet. In any case, it should have been decided much earlier than after years in Starfleet whether he was alive or not. And Data should have made sure that no one could claim ownership on Lal before building the android.
The approval that Data is a sentient lifeform may have facilitated and accelerated the process of recognizing the rights of other artificial lifeforms, such as the nanites in TNG: "Evolution" and the Exocomps in TNG: "The Quality of Life" (although in these two cases a verdict may be still pending). Voyager's EMH too was struggling for acceptance in the first season of the series, until he was finally granted the right to decide for himself when to go offline. Much like Data in "The Measure of a Man", the EMH set a precedence for holograms to be recognized as individuals with individual rights in VOY: "Author, Author". Acknowledging the rights of new lifeforms is an ongoing process in the Federation, and there is no foreseeable end to it.
Furthermore, in some cases it may have severe consequences for human beings if they had to respect the rights of evolving artificial life, possibly at the expense of their security or even their own lives. TNG: "Evolution" almost turned into a disaster, and we may only speculate what would have happened if the Enterprise-D had chosen a less moderate way to procreate in TNG: "Emergence". Like already V'ger, the evolving artificial intelligences of TNG seem to have forgotten or to ignore the respect for biological lifeforms, although something like "ethical subroutines" must have belonged to their original programming. Even though shown in an overall positive light this time (as "evolution" is unequivocally deemed a worthwhile process in Trek), there is still something incalculable about artificial life, like a remainder of the villainous machines of TOS. Even Data himself occasionally runs amuck, notably in "Brothers" and in "Insurrection". While we should not forget that human beings are overall much more "fault-prone", the severity of machine faults is much higher, especially when fail-safe mechanisms fail or are overridden. But seeing that no one would generally mistrust holodecks either, although these fail quite often (actually much too often to be still considered safe), the possible fear of androids and other artificial lifeforms should not be a reason for the Federation to impede their development.
Androids, computers and other intelligent machines were predominantly seen as technology in the 1960s and not so much as possible sentient beings. If they exhibited characteristics of human beings in the time of TOS, it almost customarily endangered the human crew, which became a cliché of TOS. But their possibly villainous behavior was not condemned because the androids or other machines acted just within the boundaries of their programming. This changed with Data. Since the remarkable episode "The Measure of a Man" there is an ongoing trend to recognize the rights not only of androids but also of other artificial lifeforms such as holograms. While technology runs out of control just as frequently as in TOS, in the 24th century the question whether androids and machines can surpass their original programming is in the focus of interest.
Overall the 24th century seems to be somewhat more open-minded about artificial lifeforms. However, this may be due to the real-world development, in which today's computers are far more advanced than anyone could have imagined in the 1960s. This leaves the question whether computers may become sentient as an even more interesting science fiction issue than it was in the time of TOS.